Part Number Hot Search : 
TB656 LH28F S925AIP 224M0 144925 F103C8T6 FN3337 91000
Product Description
Full Text Search
 

To Download PIC16LF628A-EML Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2002 microchip technology inc. preliminary ds40044a pic16f627a/628a/648a data sheet flash-based 8-bit cmos microcontrollers
ds40044a - page ii preliminary ? 2002 microchip technology inc. information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. no representation or warranty is given and no liability is assumed by microchip technology incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. use of microchip?s products as critical com- ponents in life support systems is not authorized except with express written approval by microchip. no licenses are con- veyed, implicitly or otherwise, under any intellectual property rights. trademarks the microchip name and logo, the microchip logo, k ee l oq , mplab, pic, picmicro, picstart and pro mate are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, micro id , mxdev, mxlab, picmaster, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. dspic, dspicdem.net, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, microport, migratable memory, mpasm, mplib, mplink, mpsim, picc, picdem, picdem.net, rfpic, select mode and total endurance are trademarks of microchip technology incorporated in the u.s.a. and other countries. serialized quick turn programming (sqtp) is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2002, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. microchip received qs-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona in july 1999 and mountain view, california in march 2002. the company?s quality system processes and procedures are qs-9000 compliant for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, non-volatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001 certified. note the following details of the code protection feature on microchip devices:  microchip products meet the specification contained in their particular microchip data sheet.  microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our know l- edge, require using the microchip products in a manner outside the operating specifications contained in microchip's data sheets. most likely, the person doing so is engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semiconductor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are committed to continuously improving the code protection features of our products.
? 2002 microchip technology inc. preliminary ds40044a-page 1 pic16f627a/628a/648a high performance risc cpu:  operating speeds from dc - 20 mhz  interrupt capability  8-level deep hardware stack  direct, indirect and relative addressing modes  35 single word instructions - all instructions single cycle except branches special microcontroller features:  internal and external oscillator options - precision internal 4 mhz oscillator factory calibrated to 1% - low power internal 37 khz oscillator - external oscillator support for crystals and resonators.  power saving sleep mode  programmable weak pull-ups on portb  multiplexed master clear/input-pin  watchdog timer with independent oscillator for reliable operation  low voltage programming  in-circuit serial programming? (via two pins)  programmable code protection  brown-out reset  power-on reset  power-up timer and oscillator start-up timer  wide operating voltage range. (2.0 - 5.5v)  industrial and extended temperature range  high endurance flash/eeprom cell - 100,000 write flash endurance - 1,000,000 write eeprom endurance - 100 year data retention low power features:  standby current: - 100 na @ 2.0v, typical  operating current: -12 a @ 32 khz, 2.0v, typical -120 a @ 1 mhz, 2.0v, typical  watchdog timer current -1 a @ 2.0v, typical  timer1 oscillator current: -1.2 a @ 32 khz, 2.0v, typical  dual speed internal oscillator: - run-time selectable between 4 mhz and 37 khz -4 s wake-up from sleep, 3.0v, typical peripheral features:  16 i/o pins with individual direction control  high current sink/source for direct led drive  analog comparator module with: - two analog comparators - programmable on-chip voltage reference (v ref ) module - selectable internal or external reference - comparator outputs are externally accessible  timer0: 8-bit timer/counter with 8-bit programmable prescaler  timer1: 16-bit timer/counter with external crystal/ clock capability  timer2: 8-bit timer/counter with 8-bit period regis- ter, prescaler and postscaler  capture, compare, pwm module - 16-bit capture/compare - 10-bit pwm  addressable universal synchronous/asynchro- nous receiver/transmitter usart/sci device program memory data memory i/o ccp (pwm) usart comparators timers 8/16-bit flash (words) sram (bytes) eeprom (bytes) pic16f627a 1024 224 128 16 1 y 2 2/1 pic16f628a 2048 224 128 16 1 y 2 2/1 pic16f648a 4096 256 256 16 1 y 2 2/1 18-pin flash-based 8-bit cmos microcontrollers
pic16f627a/628a/648a ds40044a-page 2 preliminary ? 2002 microchip technology inc. pin diagrams 19 18 16 15 14 13 12 11 17 20 pdip, soic ssop pic16f627a/628a/648a ra6/osc2/clkout ra7/osc1/clkin v ss v ss v dd v dd ra1/an1 ra0/an0 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd rb1/rx/dt rb2/tx/ck rb3/ccp1 rb4/pgm rb5 ra3/an3/cmp1 ra4/tocki/cmp2 ra5/mclr /v pp rb0/int ra2/an2/v ref v ss rb1/rx/dt rb2/tx/ck rb3/ccp1 ra3/an3/cmp1 ra4/tocki/cmp2 ra5/mclr /v pp rb0/int ra2/an2/v ref ra6/osc2/clkout ra7/osc1/clkin v dd ra1/an1 ra0/an0 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd rb4/pgm rb5 pic16f627a/628a/648a nc nc 28 27 26 25 24 23 1 2 3 4 5 6 7 8 9 10 11 22 21 20 19 18 17 16 15 14 13 12 ra2/an2/v ref ra3/an3/cmp1 ra4/t0cki/cmp2 ra5/mclr /v dd v ss rb0/int rb1/rx/dt rb2/tx/ck rb3/ccp1 ra1/an1 ra0/an0 ra7/osc1/clkin ra6/osc2/clkout rb7/t1osi/pgd rb6/t1oso/t1cki/pgc rb5 v dd rb4/pgm v ss nc nc nc nc nc nc v dd pic16f627a/628a pic16f648a 28-pin qfn 2 3 4 5 6 7 8 9 118 17 15 14 13 12 11 10 16 2 3 4 5 6 7 8 9 10 1 pic16f627a/628a/648a
? 2002 microchip technology inc. preliminary ds40044a-page 3 pic16f627a/628a/648a table of contents 1.0 general description......................................................................................................... ............................................................. 5 2.0 pic16f627a/628a/648a device varieties ....................................................................................... ............................................ 7 3.0 architectural overview ...................................................................................................... ........................................................... 9 4.0 memory organization ......................................................................................................... ........................................................ 15 5.0 i/o ports ................................................................................................................... .................................................................. 31 6.0 timer0 module ............................................................................................................... ............................................................ 45 7.0 timer1 module ............................................................................................................... ............................................................ 48 8.0 timer2 module ............................................................................................................... ............................................................ 52 9.0 capture/compare/pwm (ccp) module ............................................................................................ ......................................... 55 10.0 comparator module.......................................................................................................... .......................................................... 61 11.0 voltage reference module................................................................................................... ...................................................... 67 12.0 universal synchronous asynchronous receiver transmitter (usart) module..................................................... ................... 69 13.0 data eeprom memory ......................................................................................................... .................................................... 89 14.0 special features of the cpu................................................................................................ ...................................................... 93 15.0 instruction set summary .................................................................................................... ...................................................... 111 16.0 development support........................................................................................................ ....................................................... 125 17.0 electrical specifications.................................................................................................. .......................................................... 131 18.0 dc and ac characteristics graphs and tables................................................................................ ....................................... 147 19.0 packaging information...................................................................................................... ........................................................ 149 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro - chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be re fined and enhanced as new volumes and updates are introduced. if you have any questions or comments regarding this publication, please contact the marketing communications department via e-mail at docerrors@mail.microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data sheet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the version number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following:  microchip?s worldwide web site; http://www.microchip.com  your local microchip sales office (see last page)  the microchip corporate literature center; u.s. fax: (480) 792-7277 when contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (inclu de lit- erature number) you are using. customer notification system register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
pic16f627a/628a/648a ds40044a-page 4 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 5 pic16f627a/628a/648a 1.0 general description the pic16f627a/628a/648a are 18-pin flash- based members of the versatile pic16cxx family of low cost, high performance, cmos, fully-static, 8-bit microcontrollers. all picmicro ? microcontrollers employ an advanced risc architecture. the pic16f627a/628a/648a have enhanced core features, eight-level deep stack, and multiple internal and external interrupt sources. the separate instruction and data buses of the harvard architecture allow a 14-bit wide instruction word with the separate 8-bit wide data. the two-stage instruction pipeline allows all instructions to execute in a single- cycle, except for program branches (which require two cycles). a total of 35 instructions (reduced instruction set) are available, complemented by a large register set. pic16f627a/628a/648a microcontrollers typically achieve a 2:1 code compression and a 4:1 speed improvement over other 8-bit microcontrollers in their class. pic16f627a/628a/648a devices have integrated fea- tures to reduce external components, thus reducing system cost, enhancing system reliability and reducing power consumption. the pic16f627a/628a/648a has 8 oscillator configu- rations. the single-pin rc oscillator provides a low cost solution. the lp oscillator minimizes power consump- tion, xt is a standard crystal, and intosc is a self- contained precision two-speed internal oscillator. the hs is for high-speed crystals. the ec mode is for an external clock source. the sleep (power-down) mode offers power savings. users can wake-up the chip from sleep through sev- eral external interrupts, internal interrupts and resets. a highly reliable watchdog timer with its own on-chip rc oscillator provides protection against software lock- up. table 1-1 shows the features of the pic16f627a/ 628a/648a mid-range microcontroller families. a simplified block diagram of the pic16f627a/628a/ 648a is shown in figure 3-1. the pic16f627a/628a/648a series fits in applications ranging from battery chargers to low power remote sensors. the flash technology makes customizing application programs (detection levels, pulse genera- tion, timers, etc.) extremely fast and convenient. the small footprint packages makes this microcontroller series ideal for all applications with space limitations. low cost, low power, high performance, ease of use and i/o flexibility make the pic16f627a/628a/648a very versatile. 1.1 development support the pic16f627a/628a/648a family is supported by a full-featured macro assembler, a software simulator, an in-circuit emulator, a low cost in-circuit debugger, a low cost development programmer and a full-featured pro- grammer. a third party ?c? compiler support tool is also available. table 1-1: pic16f627a/628a/648a family of devices pic16f627a pic16f628a pic16f648a pic16lf627a pic16lf628a pic16lf648a clock maximum frequency of operation (mhz) 20 20 20 4 4 4 flash program mem- ory (words) 1024 2048 4096 1024 2048 4096 memory ram data memory (bytes) 224 224 256 224 224 256 eeprom data mem- ory (bytes) 128 128 256 128 128 256 timer module(s) tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 comparator(s) 222222 peripherals capture/compare/ pwm modules 111111 serial communications usart usart usart usart usart usart internal voltage reference yes yes yes yes yes yes interrupt sources 10 10 10 10 10 10 i/o pins 16 16 16 16 16 16 features voltage range (volts) 3.0-5.5 3.0-5.5 3.0-5.5 2.0-5.5 2.0-5.5 2.0-5.5 brown-out reset yes yes yes yes yes yes packages 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn all picmicro? family devices have power-on reset, selectable watchdog timer, selectable code protect and high i/o current capab ility. all pic16f627a/628a/648a family devices use serial programming with clock pin rb6 and data pin rb7.
pic16f627a/628a/648a ds40044a-page 6 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 7 pic16f627a/628a/648a 2.0 pic16f627a/628a/648a device varieties a variety of frequency ranges and packaging options are available. depending on application and production requirements, the proper device option can be selected using the information in the pic16f627a/628a/648a product identification system, at the end of this data sheet. when placing orders, please use this page of the data sheet to specify the correct part number. 2.1 flash devices flash devices can be erased and re-programmed electrically. this allows the same device to be used for prototype development, pilot programs and production. a further advantage of the electrically erasable flash is that it can be erased and reprogrammed in-circuit, or by device programmers, such as microchip's picstart ? plus, or pro mate ? ii programmers. 2.2 quick-turnaround-production (qtp) devices microchip offers a qtp programming service for factory production orders. this service is made available for users who chose not to program a medium to high quantity of units and whose code patterns have stabilized. the devices are standard flash devices but with all program locations and configuration options already programmed by the factory. certain code and prototype verification procedures apply before production shipments are available. please contact your microchip technology sales office for more details. 2.3 serialized quick-turnaround- production (sqtp sm ) devices microchip offers a unique programming service where a few user-defined locations in each device are programmed with different serial numbers. the serial numbers may be random, pseudo-random or sequential. serial programming allows each device to have a unique number, which can serve as an entry-code, password or id number.
pic16f627a/628a/648a ds40044a-page 8 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 9 pic16f627a/628a/648a 3.0 architectural overview the high performance of the pic16f627a/628a/648a family can be attributed to a number of architectural features commonly found in risc microprocessors. to begin with, the pic16f627a/628a/648a uses a har- vard architecture, in which program and data are accessed from separate memories using separate bus- ses. this improves bandwidth over traditional von neu- mann architecture where program and data are fetched from the same memory. separating program and data memory further allows instructions to be sized differ- ently than 8-bit wide data word. instruction opcodes are 14-bits wide making it possible to have all single word instructions. a 14-bit wide program memory access bus fetches a 14-bit instruction in a single cycle. a two- stage pipeline overlaps fetch and execution of instruc- tions. consequently, all instructions (35) execute in a single-cycle (200 ns @ 20 mhz) except for program branches. table 3-1 lists device memory sizes (flash, data and eeprom). table 3-1: device memory list the pic16f627a/628a/648a can directly or indirectly address its register files or data memory. all special function registers, including the program counter, are mapped in the data memory. the pic16f627a/628a/ 648a have an orthogonal (symmetrical) instruction set that makes it possible to carry out any operation, on any register, using any addressing mode. this sym- metrical nature and lack of ?special optimal situations? make programming with the pic16f627a/628a/648a simple yet efficient. in addition, the learning curve is reduced significantly. the pic16f627a/628a/648a devices contain an 8-bit alu and working register. the alu is a general pur- pose arithmetic unit. it performs arithmetic and boolean functions between data in the working register and any register file. the alu is 8-bit wide and capable of addition, subtraction, shift and logical operations. unless otherwise mentioned, arithmetic operations are two's complement in nature. in two-operand instructions, typically one operand is the working register (w register). the other operand is a file register or an immediate constant. in single operand instructions, the operand is either the w register or a file register. the w register is an 8-bit working register used for alu operations. it is not an addressable register. depending on the instruction executed, the alu may affect the values of the carry (c), digit carry (dc), and zero (z) bits in the status register. the c and dc bits operate as a borrow and digit borrow out bit, respectively, bit in subtraction. see the sublw and subwf instructions for examples. a simplified block diagram is shown in figure 3-1, and a description of the device pins in table 3-2. two types of data memory are provided on the pic16f627a/628a/648a devices. non-volatile eeprom data memory is provided for long term stor- age of data such as calibration values, look up table data, and any other data which may require periodic updating in the field. these data are not lost when power is removed. the other data memory provided is regular ram data memory. regular ram data memory is provided for temporary storage of data during normal operation. data are lost when power is removed. device memory flash program ram data eeprom data pic16f627a 1024 x 14 224 x 8 128 x 8 pic16f628a 2048 x 14 224 x 8 128 x 8 pic16f648a 4096 x 14 256 x 8 256 x 8 pic16lf627a 1024 x 14 224 x 8 128 x 8 pic16lf628a 2048 x 14 224 x 8 128 x 8 pic16lf648a 4096 x 14 256 x 8 256 x 8
pic16f627a/628a/648a ds40044a-page 10 preliminary ? 2002 microchip technology inc. figure 3-1: block diagram note: higher order bits are from the status register. flash program memory 13 data bus 8 14 program bus instruction reg program counter 8-level stack (13-bit) ram file registers direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clkin osc2/clkout mclr v dd , v ss porta portb ra4/t0ck1/cmp2 ra5/mclr /v pp rb0/int 8 8 brown-out detect usart ccp1 timer0 timer1 timer2 ra3/an3/cmp1 ra2/an2/v ref ra1/an1 ra0/an0 8 3 rb1/rx/dt rb2/tx/ck rb3/ccp1 rb4/pgm rb5 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd low-voltage programming ra6/osc2/clkout ra7/osc1/clkin v ref comparator data eeprom
? 2002 microchip technology inc. preliminary ds40044a-page 11 pic16f627a/628a/648a table 3-2: pic16f627a/628a/648a pinout description name function input type output type description ra0/an0 ra0 st cmos bi-directional i/o port an0 an ? analog comparator input ra1/an1 ra1 st cmos bi-directional i/o port an1 an ? analog comparator input ra2/an2/v ref ra2 st cmos bi-directional i/o port an2 an ? analog comparator input v ref ?anv ref output ra3/an3/cmp1 ra3 st cmos bi-directional i/o port an3 an ? analog comparator input cmp1 ? cmos comparator 1 output ra4/t0cki/cmp2 ra4 st od bi-directional i/o port t0cki st ? timer0 clock input cmp2 ? od comparator 2 output ra5/mclr /v pp ra5 st ? input port mclr st ? master clear. when configured as mclr , this pin is an active low reset to the device. voltage on mclr /v pp must not exceed v dd during normal device operation. v pp ? ? programming voltage input. ra6/osc2/clkout ra6 st cmos bi-directional i/o port osc2 ? xtal oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. clkout ? cmos in rc/intosc mode, osc2 pin can output clkout, which has 1/4 the frequency of osc1 ra7/osc1/clkin ra7 st cmos bi-directional i/o port osc1 xtal ? oscillator crystal input clkin st ? external clock source input. rc biasing pin. rb0/int rb0 ttl cmos bi-directional i/o port. can be software pro- grammed for internal weak pull-up. int st ? external interrupt. rb1/rx/dt rb1 ttl cmos bi-directional i/o port. can be software pro- grammed for internal weak pull-up. rx st ? usart receive pin dt st cmos synchronous data i/o. rb2/tx/ck rb2 ttl cmos bi-directional i/o port. can be software pro- grammed for internal weak pull-up. tx ? cmos usart transmit pin ck st cmos synchronous clock i/o. rb3/ccp1 rb3 ttl cmos bi-directional i/o port. can be software pro- grammed for internal weak pull-up. ccp1 st cmos capture/compare/pwm i/o legend: o = output cmos = cmos output p = power ? = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog
pic16f627a/628a/648a ds40044a-page 12 preliminary ? 2002 microchip technology inc. rb4/pgm rb4 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. pgm st ? low voltage programming input pin. when low voltage programming is enabled, the interrupt-on-pin change and weak pull-up resistor are disabled. rb5 rb5 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. rb6/t1oso/t1cki/pgc rb6 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1oso ? xtal timer1 oscillator output. t1cki st ? timer1 clock input. pgc st ? icsp programming clock. rb7/t1osi/pgd rb7 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1osi xtal ? timer1 oscillator input. pgd st cmos icsp data i/o v ss v ss power ? ground reference for logic and i/o pins v dd v dd power ? positive supply for logic and i/o pins table 3-2: pic16f627a/628a/648a pinout description name function input type output type description legend: o = output cmos = cmos output p = power ? = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog
? 2002 microchip technology inc. preliminary ds40044a-page 13 pic16f627a/628a/648a 3.1 clocking scheme/instruction cycle the clock input (osc1/clkin/ra7 pin) is internally divided by four to generate four non-overlapping quadrature clocks namely q1, q2, q3 and q4. inter- nally, the program counter (pc) is incremented every q1, the instruction is fetched from the program memory and latched into the instruction register in q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow is shown in figure 3-2. 3.2 instruction flow/pipelining an instruction cycle consists of four q cycles (q1, q2, q3 and q4). the instruction fetch and execute are pipelined such that fetch takes one instruction cycle while decode and execute takes another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction causes the program counter to change (e.g., goto ) then two cycles are required to complete the instruction (example 3-1). a fetch cycle begins with the program counter (pc) incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3, and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 3-2: clock/instruction cycle example 3-1: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc clkout pc pc+1 pc+2 fetch inst (pc) execute inst (pc-1) fetch inst (pc+1) execute inst (pc) fetch inst (pc+2) execute inst (pc+1) internal phase clock all instructions are single cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. call sub_1 fetch 3 execute 3 4. bsf porta, 3 fetch 4 flush fetch sub_1 execute sub_1
pic16f627a/628a/648a ds40044a-page 14 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 15 pic16f627a/628a/648a 4.0 memory organization 4.1 program memory organization the pic16f627a/628a/648a has a 13-bit program counter capable of addressing an 8k x 14 program memory space. only the first 1k x 14 (0000h - 03ffh) for the pic16f627a, 2k x 14 (0000h - 07ffh) for the pic16f628a and 4k x 14 (0000h - 0fffh) for the pic16f648a are physically implemented. accessing a location above these boundaries will cause a wrap- around within the first 1k x 14 space (pic16f627a), 2k x 14 space (pic16f628a) or 4k x 14 space (pic16f648a). the reset vector is at 0000h and the interrupt vector is at 0004h (figure 4-1). figure 4-1: program memory map and stack 4.2 data memory organization the data memory (figure 4-2 and figure 4-3) is partitioned into four banks, which contain the general purpose registers and the special function registers (sfr). the sfr?s are located in the first 32 locations of each bank. there are general purpose registers imple- mented as static ram in each bank. table 4-1 lists the general purpose register available in each of the four banks. table 4-1: general purpose static ram registers addresses f0h-ffh, 170h-17fh and 1f0h-1ffh are implemented as common ram and mapped back to addresses 70h-7fh. table 4-2 lists how to access the four banks of registers via the status register bits rp1 and rp0. table 4-2: access to banks of registers 4.2.1 general purpose register file the register file is organized as 224 x 8 in the pic16f627a/628a and 256 x 8 in the pic16f648a. each is accessed either directly or indirectly through the file select register (fsr), see section 4.4. pc<12:0> 13 000h 0004 0005 03ffh 1fffh stack level 1 stack level 8 reset vector interrupt vector on-chip program memory call, return retfie, retlw stack level 2 07ffh pic16f627a, pic16f628a and pic16f648a on-chip program memory pic16f628a and pic16f648a on-chip program memory pic16f648a only 0fffh pic16f627a/628a pic16f648a bank0 20-7fh 20-7fh bank1 a0h-ff a0h-ff bank2 120h-14fh, 170h-17fh 120h-17fh bank3 1f0h-1ffh 1f0h-1ffh rp1 rp0 bank0 00 bank1 01 bank2 10 bank3 11
pic16f627a/628a/648a ds40044a-page 16 preliminary ? 2002 microchip technology inc. figure 4-2: data memory map of the pic16f627a and pic16f628a indirect addr. (1) tmr0 pcl status fsr porta portb pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h ccp1con option pcl status fsr trisa trisb pclath intcon pie1 pcon pr2 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 unimplemented data memory locations, read as '0'. note 1: not a physical register. file address indirect addr. (1) indirect addr. (1) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 10ch 10dh 10eh 10fh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 18ch 18dh 18eh 18fh 17fh 1ffh bank 2 bank 3 indirect addr. (1) tmr0 option rcsta txreg rcreg cmcon txsta spbrg vrcon general purpose register 1efh 1f0h accesses 70h - 7fh efh f0h accesses 70h-7fh 16fh 170h accesses 70h-7fh 80 bytes eedata eeadr eecon1 eecon2 (1) general purpose register 80 bytes general purpose register 48 bytes 11fh 120h 14fh 150h 6fh 70h 16 bytes portb trisb 1ch 1dh 1eh
? 2002 microchip technology inc. preliminary ds40044a-page 17 pic16f627a/628a/648a figure 4-3: data memory map of the pic16f648a indirect addr. (1) tmr0 pcl status fsr porta portb pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h ccp1con option pcl status fsr trisa trisb pclath intcon pie1 pcon pr2 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 unimplemented data memory locations, read as '0'. note 1: not a physical register. file address indirect addr. (1) indirect addr. (1) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 10ch 10dh 10eh 10fh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 18ch 18dh 18eh 18fh 17fh 1ffh bank 2 bank 3 indirect addr. (1) tmr0 option rcsta txreg rcreg cmcon txsta spbrg vrcon general purpose register 1efh 1f0h accesses 70h - 7fh efh f0h accesses 70h-7fh 16fh 170h accesses 70h-7fh 80 bytes eedata eeadr eecon1 eecon2 (1) general purpose register 80 bytes 11fh 120h 6fh 70h 16 bytes portb trisb 1ch 1dh 1eh general purpose register 80 bytes
pic16f627a/628a/648a ds40044a-page 18 preliminary ? 2002 microchip technology inc. 4.2.2 special function registers the sfrs are registers used by the cpu and periph- eral functions for controlling the desired operation of the device (table 4-3). these registers are static ram. the special registers can be classified into two sets (core and peripheral). the sfrs associated with the ?core? functions are described in this section. those related to the operation of the peripheral features are described in the section of that peripheral feature. table 4-3: special registers summary bank0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 0 00h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 28 01h tmr0 timer0 modules register xxxx xxxx 45 02h pcl program counter's (pc) least significant byte 0000 0000 28 03h status irp rp1 rp0 to pd zdc c 0001 1xxx 22 04h fsr indirect data memory address pointer xxxx xxxx 28 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx 0000 31 06h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 36 07h unimplemented 08h unimplemented 09h unimplemented 0ah pclath write buffer for upper 5 bits of program counter ---0 0000 28 0bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 24 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 26 0dh unimplemented 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 xxxx xxxx 48 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 xxxx xxxx 48 10h t1con t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 48 11h tmr2 tmr2 modules register 0000 0000 52 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 52 13h unimplemented 14h unimplemented 15h ccpr1l capture/compare/pwm register (lsb) xxxx xxxx 55 16h ccpr1h capture/compare/pwm register (msb) xxxx xxxx 55 17h ccp1con ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 55 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 69 19h txreg usart transmit data register 0000 0000 76 1ah rcreg usart receive data register 0000 0000 79 1bh unimplemented 1ch unimplemented 1dh unimplemented 1eh unimplemented 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 61 legend: ? = unimplemented locations read as ?0?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14-7.
? 2002 microchip technology inc. preliminary ds40044a-page 19 pic16f627a/628a/648a table 4-4: special function registers summary bank1 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 1 80h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 28 81h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 23 82h pcl program counter's (pc) least significant byte 0000 0000 28 83h status irp rp1 rp0 to pd zdcc 0001 1xxx 22 84h fsr indirect data memory address pointer xxxx xxxx 28 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 31 86h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 36 87h unimplemented 88h unimplemented 89h unimplemented 8ah pclath write buffer for upper 5 bits of program counter ---0 0000 28 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 24 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 25 8dh unimplemented 8eh pcon oscf por bor ---- 1-0x 27 8fh unimplemented 90h unimplemented 91h unimplemented 92h pr2 timer2 period register 1111 1111 52 93h unimplemented 94h unimplemented 95h unimplemented 96h unimplemented 97h unimplemented 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 71 99h spbrg baud rate generator register 0000 0000 71 9ah eedata eeprom data register xxxx xxxx 89 9bh eeadr eeprom address register xxxx xxxx 90 9ch eecon1 wrerr wren wr rd ---- x000 90 9dh eecon2 eeprom control register 2 (not a physical register) ---- ---- 90 9eh unimplemented 9fh vrcon vren vroe vrr vr3 vr2 vr1 vr0 000- 0000 67 legend: ? = unimplemented locations read as ?0?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14-7.
pic16f627a/628a/648a ds40044a-page 20 preliminary ? 2002 microchip technology inc. table 4-5: special function registers summary bank2 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 2 100h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 28 101h tmr0 timer0 modules register xxxx xxxx 45 102h pcl program counter's (pc) least significant byte 0000 0000 28 103h status irp rp1 rp0 to pd zdcc 0001 1xxx 22 104h fsr indirect data memory address pointer xxxx xxxx 28 105h unimplemented 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 36 107h unimplemented 108h unimplemented 109h unimplemented 10ah pclath write buffer for upper 5 bits of program counter ---0 0000 28 10bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 24 10ch unimplemented 10dh unimplemented 10eh unimplemented 10fh unimplemented 110h unimplemented 111h unimplemented 112h unimplemented 113h unimplemented 114h unimplemented 115h unimplemented 116h unimplemented 117h unimplemented 118h unimplemented 119h unimplemented 11ah unimplemented 11bh unimplemented 11ch unimplemented 11dh unimplemented 11eh unimplemented 11fh unimplemented legend: ? = unimplemented locations read as ?0?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented. note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14-7.
? 2002 microchip technology inc. preliminary ds40044a-page 21 pic16f627a/628a/648a table 4-6: special function registers summary bank3 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 3 180h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 28 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 23 182h pcl program counter's (pc) least significant byte 0000 0000 28 183h status irp rp1 rp0 to pd zdcc 0001 1xxx 22 184h fsr indirect data memory address pointer xxxx xxxx 28 185h unimplemented 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 36 187h unimplemented 188h unimplemented 189h unimplemented 18ah pclath write buffer for upper 5 bits of program counter ---0 0000 28 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 24 18ch unimplemented 18dh unimplemented 18eh unimplemented 18fh unimplemented 190h unimplemented 191h unimplemented 192h unimplemented 193h unimplemented 194h unimplemented 195h unimplemented 196h unimplemented 197h unimplemented 198h unimplemented 199h unimplemented 19ah unimplemented 19bh unimplemented 19ch unimplemented 19dh unimplemented 19eh unimplemented 19fh unimplemented legend: ? = unimplemented locations read as ?0?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14-7.
pic16f627a/628a/648a ds40044a-page 22 preliminary ? 2002 microchip technology inc. 4.2.2.1 status register the status register, shown in register 4-1, contains the arithmetic status of the alu; the reset status and the bank select bits for data memory (sram). the status register can be the destination for any instruction, like any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are non- writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper-three bits and set the z bit. this leaves the status register as ?000uu1uu? (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register because these instructions do not affect any status bit. for other instructions, not affecting any status bits, see the ?instruction set summary?. register 4-1: status register (address: 03h, 83h, 103h, 183h) note 1: the c and dc bits operate as a borrow and digit borrow out bit, respectively, in subtraction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdcc bit 7 bit 0 bit 7 irp : register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h - 1ffh) 0 = bank 0, 1 (00h - ffh) bit 6-5 rp1:rp0 : register bank select bits (used for direct addressing) 00 = bank 0 (00h - 7fh) 01 = bank 1 (80h - ffh) 10 = bank 2 (100h - 17fh) 11 = bank 3 (180h - 1ffh) bit 4 to : time out bit 1 = after power-up, clrwdt instruction, or sleep instruction 0 = a wdt time out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z : zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc : digit carry/borrow bit ( addwf , addlw,sublw,subwf instructions) (for borrow the polarity is reversed) 1 = a carry-out from the 4th low order bit of the result occurred 0 = no carry-out from the 4th low order bit of the result bit 0 c : carry/borrow bit ( addwf , addlw,sublw,subwf instructions) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for borrow , the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 23 pic16f627a/628a/648a 4.2.2.2 option register the option register is a readable and writable register, which contains various control bits to configure the tmr0/wdt prescaler, the external rb0/int interrupt, tmr0 and the weak pull-ups on portb. register 4-2: option register (address: 81h, 181h) note: to achieve a 1:1 prescaler assignment for tmr0, assign the prescaler to the wdt (psa = 1). see section 6.3.1. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg : interrupt edge select bit 1 = interrupt on rising edge of rb0/int pin 0 = interrupt on falling edge of rb0/int pin bit 5 t0cs : tmr0 clock source select bit 1 = transition on ra4/t0cki pin 0 = internal instruction cycle clock (clkout) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/t0cki pin 0 = increment on low-to-high transition on ra4/t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps2:ps0 : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
pic16f627a/628a/648a ds40044a-page 24 preliminary ? 2002 microchip technology inc. 4.2.2.3 intcon register the intcon register is a readable and writable register, which contains the various enable and flag bits for all interrupt sources except the comparator module. see section 4.2.2.4 and section 4.2.2.5 for a description of the comparator enable and flag bits. register 4-3: intcon register (address: 0bh, 8bh, 10bh, 18bh) note: interrupt flag bits get set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie t0ie inte rbie t0if intf rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all un-masked interrupts 0 = disables all interrupts bit 6 peie : peripheral interrupt enable bit 1 = enables all un-masked peripheral interrupts 0 = disables all peripheral interrupts bit 5 t0ie : tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 inte : rb0/int external interrupt enable bit 1 = enables the rb0/int external interrupt 0 = disables the rb0/int external interrupt bit 3 rbie : rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 t0if : tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf : rb0/int external interrupt flag bit 1 = the rb0/int external interrupt occurred (must be cleared in software) 0 = the rb0/int external interrupt did not occur bit 0 rbif : rb port change interrupt flag bit 1 = when at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 25 pic16f627a/628a/648a 4.2.2.4 pie1 register this register contains interrupt enable bits. register 4-4: pie1 register (address: 8ch) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 eeie: ee write complete interrupt enable bit 1 = enables the ee write complete interrupt 0 = disables the ee write complete interrupt bit 6 cmie : comparator interrupt enable bit 1 = enables the comparator interrupt 0 = disables the comparator interrupt bit 5 rcie : usart receive interrupt enable bit 1 = enables the usart receive interrupt 0 = disables the usart receive interrupt bit 4 txie : usart transmit interrupt enable bit 1 = enables the usart transmit interrupt 0 = disables the usart transmit interrupt bit 3 unimplemented : read as ?0? bit 2 ccp1ie : ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie : tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie : tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 26 preliminary ? 2002 microchip technology inc. 4.2.2.5 pir1 register this register contains interrupt flag bits. register 4-5: pir1 register (address: 0ch) note: interrupt flag bits get set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r-0 r-0 u-0 r/w-0 r/w-0 r/w-0 eeif cmif rcif txif ? ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 eeif: eeprom write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation has not completed or has not been started bit 6 cmif : comparator interrupt flag bit 1 = comparator output has changed 0 = comparator output has not changed bit 5 rcif : usart receive interrupt flag bit 1 = the usart receive buffer is full 0 = the usart receive buffer is empty bit 4 txif : usart transmit interrupt flag bit 1 = the usart transmit buffer is empty 0 = the usart transmit buffer is full bit 3 unimplemented : read as ?0? bit 2 ccp1if : ccp1 interrupt flag bit capture mode 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode unused in this mode bit 1 tmr2if : tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if : tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 27 pic16f627a/628a/648a 4.2.2.6 pcon register the pcon register contains flag bits to differentiate between a power-on reset, an external mclr reset, wdt reset or a brown-out reset. register 4-6: pcon register (address: 8eh) note: bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor is cleared, indicating a brown-out has occurred. the bor status bit is a ?don't care? and is not necessarily predictable if the brown-out circuit is disabled (by clearing the boren bit in the configuration word). u-0 u-0 u-0 u-0 r/w-1 u-0 r/w-0 r/w-x ? ? ? ? oscf ?por bor bit 7 bit 0 bit 7-4 unimplemented: read as '0' bit 3 oscf : intosc oscillator frequency 1 = 4 mhz typical 0 = 37 khz typical bit 2 unimplemented: read as '0' bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 28 preliminary ? 2002 microchip technology inc. 4.3 pcl and pclath the program counter (pc) is 13-bits wide. the low byte comes from the pcl register, which is a readable and writable register. the high byte (pc<12:8>) is not directly readable or writable and comes from pclath. on any reset, the pc is cleared. figure 4-4 shows the two situations for loading the pc. the upper exam- ple in figure 4-4 shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in figure 4-4 shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 4-4: loading of pc in different situations 4.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when doing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note ?implementing a table read? (an556). 4.3.2 stack the pic16f627a/628a/648a family has an 8-level deep x 13-bit wide hardware stack (figure 4-1). the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return, retlw or a ret- fie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 4.4 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf reg- ister. any instruction using the indf register actually accesses data pointed to by the file select register (fsr). reading indf itself indirectly will produce 00h. writing to the indf register indirectly results in a no- operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 4-5. a simple program to clear ram location 20h-2fh using indirect addressing is shown in example 4-1. example 4-1: indirect addressing pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu result goto, call opcode <10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl as destination note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call, return, retlw and retfie instructions, or the vectoring to an interrupt address. movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next ;yes continue
? 2002 microchip technology inc. preliminary ds40044a-page 29 pic16f627a/628a/648a figure 4-5: direct/indirect addressing pic16f627a/628a/648a note: for memory map detail see figure 4-3, figure 4-2 and figure 4-1. ram indirect addressing direct addressing bank select location select rp1 rp0 6 0 from opcode irp fsr register 7 0 bank select location select 00 01 10 11 180h 1ffh 00h 7fh bank 0 bank 1 bank 2 bank 3 file registers status register status register
pic16f627a/628a/648a ds40044a-page 30 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 31 pic16f627a/628a/648a 5.0 i/o ports the pic16f627a/628a/648a have two ports, porta and portb. some pins for these i/o ports are multi- plexed with alternate functions for the peripheral fea- tures on the device. in general, when a peripheral is enabled, that pin may not be used as a general pur- pose i/o pin. 5.1 iporta and trisa registers porta is an 8-bit wide latch. ra4 is a schmitt trigger input and an open drain output. port ra4 is multiplexed with the t0cki clock input. ra5 (1) is a schmitt trigger input only and has no output drivers. all other ra port pins have schmitt trigger input levels and full cmos output drivers. all pins have data direction bits (tris registers) which can configure these pins as input or output. a '1' in the trisa register puts the corresponding out- put driver in a high-impedance mode. a '0' in the trisa register puts the contents of the output latch on the selected pin(s). reading the porta register reads the status of the pins whereas writing to it will write to the port latch. all write operations are read-modify-write operations. so a write to a port implies that the port pins are first read, then this value is modified and written to the port data latch. the porta pins are multiplexed with comparator and voltage reference functions. the operation of these pins are selected by control bits in the cmcon (comparator control register) register and the vrcon (voltage reference control register) register. when selected as a comparator input, these pins will read as '0's. trisa controls the direction of the ra pins, even when they are being used as comparator inputs. the user must make sure to keep the pins configured as inputs when using them as comparator inputs. the ra2 pin will also function as the output for the voltage reference. when in this mode, the v ref pin is a very high-impedance output. the user must configure trisa<2> bit as an input and use high-impedance loads. in one of the comparator modes defined by the cmcon register, pins ra3 and ra4 become outputs of the comparators. the trisa<4:3> bits must be cleared to enable outputs to use this function. example 5-1: initializing porta figure 5-1: block diagram of ra0/an0:ra1/an1 pins note 1: ra5 shares function with v pp . when v pp voltage levels are applied to ra5, the device will enter programming mode. 2: on reset, the trisa register is set to all inputs. the digital inputs (ra<3:0>) are disabled and the comparator inputs are forced to ground to reduce current con- sumption. 3: trisa<6:7> is overridden by oscillator configuration. when porta<6:7> is overridden, the data reads ?0? and the trisa<6:7> bits are ignored. clrf porta ;initialize porta by ;setting ;output data latches movlw 0x07 ;turn comparators off and movwf cmcon ;enable pins for i/o ;functions bcf status, rp1 bsf status, rp0 ;select bank1 movlw 0x1f ;value used to initialize ;data direction movwf trisa ;set ra<4:0> as inputs ;trisa<5> always ;read as ?1?. ;trisa<7:6> ;depend on oscillator ;mode data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog i/o pin q d q ck input mode d q en to comparator schmitt trigger input buffer v dd v ss trisa (cmcon reg.)
pic16f627a/628a/648a ds40044a-page 32 preliminary ? 2002 microchip technology inc. figure 5-2: block diagram of ra2/v ref pin figure 5-3: block diagram of the ra3/an3 pin data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog ra2 pin q d q ck input mode d q en to comparator schmitt trigger input buffer v roe v ref v dd v ss trisa (cmcon reg.) data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog ra3 pin q d q ck d q en to comparator schmitt trigger input buffer input mode comparator output comparator mode = 110 v dd v ss trisa (cmcon reg.) (cmcon reg.) 1 0
? 2002 microchip technology inc. preliminary ds40044a-page 33 pic16f627a/628a/648a figure 5-4: block diagram of ra4/t0cki pin figure 5-5: block diagram of the ra5/mclr /v pp pin figure 5-6: block diagram of ra6/osc2/clkout pin data bus q d q ck n wr porta wr trisa data latch tris latch rd trisa rd porta vss ra4 pin q d q ck d q en tmr0 clock input schmitt trigger input buffer comparator output comparator mode = 110 vss v dd 1 0 (cmcon reg.) d q en hv detect mclr filter ra5/mclr /v pp mclr program mclre rd v ss data bus v ss porta rd circuit mode schmitt trigger input buffer trisa (configuration bit) wr d ck q q porta wr trisa v dd v ss clkout(f osc /4) (f osc = 101, 111) (2) qd rd en rd porta f osc = d ck q q 011, 100, 110 (1) trisa from osc1 osc circuit note 1: intosc with ra6 = i/o or rc with ra6 = i/o. 2: intosc with ra6 = clkout or rc with ra6 = clkout. schmitt trigger input buffer data latch tris latch 1 0
pic16f627a/628a/648a ds40044a-page 34 preliminary ? 2002 microchip technology inc. figure 5-7: block diagram of ra7/osc1/clkin pin data bus q d q ck wr porta wr trisa data latch tris latch rd trisa rd porta ra7/osc1/clkin pin q d q ck d q en to clock circuits f osc = 100, 101 (1) v dd v ss note 1: intosc with clkout, and intosc with i/o. schmitt trigger input buffer
? 2002 microchip technology inc. preliminary ds40044a-page 35 pic16f627a/628a/648a table 5-1: porta functions name function input type output type description ra0/an0 ra0 st cmos bi-directional i/o port an0 an ? analog comparator input ra1/an1 ra1 st cmos bi-directional i/o port an1 an ? analog comparator input ra2/an2/v ref ra2 st cmos bi-directional i/o port an2 an ? analog comparator input v ref ?anv ref output ra3/an3/cmp1 ra3 st cmos bi-directional i/o port an3 an ? analog comparator input cmp1 ? cmos comparator 1 output ra4/t0cki/cmp2 ra4 st od bi-directional i/o port. output is open drain type. t0cki st ? external clock input for tmr0 or comparator output cmp2 ? od comparator 2 output ra5/mclr /v pp ra5 st ? input port mclr st ? master clear. when configured as mclr , this pin is an active low reset to the device. voltage on mclr /v pp must not exceed v dd during normal device operation. v pp hv ? programming voltage input. ra6/osc2/clkout ra6 st cmos bi-directional i/o port osc2 ? xtal oscillator crystal output. connects to crystal resonator in crystal oscillator mode. clkout ? cmos in rc or intosc mode. osc2 pin can output clkout, which has 1/4 the frequency of osc1 ra7/osc1/clkin ra7 st cmos bi-directional i/o port osc1 xtal ? oscillator crystal input. connects to crystal resonator in crystal oscillator mode. clkin st ? external clock source input. rc biasing pin. legend: o = output cmos = cmos output p = power ? = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog
pic16f627a/628a/648a ds40044a-page 36 preliminary ? 2002 microchip technology inc. table 5-2: summary of registers associated with porta (1) 5.2 portb and trisb registers portb is an 8-bit wide bi-directional port. the corresponding data direction register is trisb. a '1' in the trisb register puts the corresponding output driver in a high-impedance mode. a '0' in the trisb register puts the contents of the output latch on the selected pin(s). portb is multiplexed with the external interrupt, usart, ccp module and the tmr1 clock input/output. the standard port functions and the alternate port func- tions are shown in table 5-3. alternate port functions may override tris setting when enabled. reading portb register reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. so a write to a port implies that the port pins are first read, then this value is modified and written to the port data latch. each of the portb pins has a weak internal pull-up ( 200 a typical). a single control bit can turn on all the pull-ups. this is done by clearing the rbpu (option<7>) bit. the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on power-on reset. four of portb?s pins, rb<7:4>, have an interrupt-on- change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb<7:4> pin con- figured as an output is excluded from the interrupt-on- change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are or?ed together to generate the rbif interrupt (flag latched in intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb. this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. this interrupt on mismatch feature, together with software configurable pull-ups on these four pins allow easy interface to a key pad and make it possible for wake-up on key-depression. (see an552) the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 05h porta ra7 ra6 ra5 (2) ra4 ra3 ra2 ra1 ra0 xxxx 0000 qqqu 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 9fh vrcon vren vroe vrr ? vr3 vr2 vr1 vr0 000- 0000 000- 0000 legend: ? = unimplemented locations read as ?0?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: shaded bits are not used by porta. 2: mclre configuration bit sets ra5 functionality. note: if a change on the i/o pin should occur when a read operation is being executed (start of the q2 cycle), then the rbif inter- rupt flag may not get set.
? 2002 microchip technology inc. preliminary ds40044a-page 37 pic16f627a/628a/648a figure 5-8: block diagram of rb0/int pin figure 5-9: block diagram of rb1/rx/dt pin data bus wr portb wr trisb rd portb data latch tris latch rb0/int int q d ck en qd en rd trisb rbpu p v dd v dd v ss q q d ck q weak pull-up schmitt ttl input buffer trigger data latch tris latch rd trisb q d q ck q d q ck 1 0 wr portb wr trisb schmitt trigger peripheral oe (1) data bus spen usart data output usart receive input rbpu v dd p en qd v dd v ss note 1: p eripheral oe (output enable) is only active if peripheral select is active. rd portb rx/dt rb1/ ttl input buffer weak pull-up
pic16f627a/628a/648a ds40044a-page 38 preliminary ? 2002 microchip technology inc. figure 5-10: block diagram of rb2/tx/ck pin figure 5-11: block diagram of rb3/ccp1 pin data latch tris latch rd trisb q d q ck q d q ck 1 0 wr portb wr trisb schmitt trigger peripheral oe (1) data bus spen usart tx/ck output usart slave clock in rbpu v dd p en qd v dd v ss note 1: p eripheral oe (output enable) is only active if peripheral select is active. rd portb ttl input buffer rb2/ tx/ck weak pull-up data latch tris latch rd trisb q d q ck q d q ck 0 1 wr portb wr trisb schmitt trigger peripheral oe (2) data bus ccp1con ccp output ccp in rbpu v dd p en qd v dd v ss note 1: p eripheral oe (output enable) is only active if peripheral select is active. rd portb ttl input buffer rb3/ ccp1 weak pull-up
? 2002 microchip technology inc. preliminary ds40044a-page 39 pic16f627a/628a/648a figure 5-12: block diagram of rb4/pgm pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb schmitt trigger pgm input lvp data bus rb4/pgm v dd weak pull-up p from other qd en qd en set rbif rb<7:4> pins ttl input buffer v dd v ss note: the low voltage programming disables the interrupt-on-change and the weak pull-ups on rb4. rbpu q1 q3 (configuration bit)
pic16f627a/628a/648a ds40044a-page 40 preliminary ? 2002 microchip technology inc. figure 5-13: block diagram of rb5 pin data bus wr portb wr trisb rd portb data latch tris latch rb5 pin ttl input buffer rd trisb rbpu p v dd weak pull-up from other qd en qd en set rbif rb<7:4> pins v dd v ss q d q ck q d q ck q1 q3
? 2002 microchip technology inc. preliminary ds40044a-page 41 pic16f627a/628a/648a figure 5-14: block diagram of rb6/t1oso/t1cki pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb schmitt trigger t1oscen data bus rb6/ tmr1 clock rbpu v dd weak pull-up p from rb7 t1oso/ t1cki pin from other qd en set rbif rb<7:4> pins serial programming clock ttl input buffer tmr1 oscillator qd en v dd v ss q3 q1
pic16f627a/628a/648a ds40044a-page 42 preliminary ? 2002 microchip technology inc. figure 5-15: block diagram of the rb7/t1osi pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb t10scen data bus rb7/t1osi to r b 6 rbpu v dd weak pull-up p pin ttl input buffer from other qd en qd en set rbif rb<7:4> pins serial programming input schmitt trigger tmr1 oscillator v dd v ss q3 q1
? 2002 microchip technology inc. preliminary ds40044a-page 43 pic16f627a/628a/648a table 5-3: portb functions table 5-4: summary of registers associated with portb (1) name function input type output type description rb0/int rb0 ttl cmos bi-directional i/o port. can be software programmed for internal weak pull-up. int st ? external interrupt. rb1/rx/dt rb1 ttl cmos bi-directional i/o port. can be software programmed for internal weak pull-up. rx st ? usart receive pin dt st cmos synchronous data i/o rb2/tx/ck rb2 ttl cmos bi-directional i/o port tx ? cmos usart transmit pin ck st cmos synchronous clock i/o. can be software programmed for internal weak pull-up. rb3/ccp1 rb3 ttl cmos bi-directional i/o port. can be software programmed for internal weak pull-up. ccp1 st cmos capture/compare/pwm/i/o rb4/pgm rb4 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. pgm st ? low voltage programming input pin. when low voltage programming is enabled, the interrupt-on-pin change and weak pull-up resistor are disabled. rb5 rb5 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. rb6/t1oso/t1cki/ pgc rb6 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1oso ? xtal timer1 oscillator output t1cki st ? timer1 clock input pgc st ? icsp programming clock rb7/t1osi/pgd rb7 ttl cmos bi-directional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1osi xtal ? timer1 oscillator input pgd st cmos icsp data i/o legend: o = output cmos = cmos output p = power ? = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 06h, 106h portb rb7 rb6 rb5 rb4 (2) rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 86h, 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 81h, 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: u = unchanged, x = unknown note 1: shaded bits are not used by portb. 2: lvp configuration bit sets rb4 functionality.
pic16f627a/628a/648a ds40044a-page 44 preliminary ? 2002 microchip technology inc. 5.3 i/o programming considerations 5.3.1 bi-directional i/o ports any instruction that writes, operates internally as a read followed by a write operation. the bcf and bsf instruc- tions, for example, read the register into the cpu, exe- cute the bit operation and write the result back to the register. caution must be used when these instructions are applied to a port with both inputs and outputs defined. for example, a bsf operation on bit5 of portb will cause all eight bits of portb to be read into the cpu. then the bsf operation takes place on bit5 and portb is written to the output latches. if another bit of portb is used as a bi-directional i/o pin (e.g., bit0) and is defined as an input at this time, the input signal present on the pin itself would be read into the cpu and rewritten to the data latch of this particular pin, overwriting the previous content. as long as the pin stays in the input mode, no problem occurs. however, if bit0 is switched into output mode later on, the content of the data latch may now be unknown. reading a port register reads the values of the port pins. writing to the port register writes the value to the port latch. when using read-modify-write instructions (ex. bcf, bsf , etc.) on a port, the value of the port pins is read, the desired operation is done to this value, and this value is then written to the port latch. example 5-2 shows the effect of two sequential read- modify-write instructions (ex., bcf, bsf , etc.) on an i/o port. a pin actively outputting a low or high should not be driven from external devices at the same time in order to change the level on this pin (?wired-or?, ?wired-and?). the resulting high output currents may damage the chip. example 5-2: read-modify-write instructions on an i/o port 5.3.2 successive operations on i/o ports the actual write to an i/o port happens at the end of an instruction cycle, whereas for reading, the data must be valid at the beginning of the instruction cycle (figure 5- 16). therefore, care must be exercised if a write fol- lowed by a read operation is carried out on the same i/ o port. the sequence of instructions should be such to allow the pin voltage to stabilize (load dependent) before the next instruction, which causes that file to be read into the cpu, is executed. otherwise, the previ- ous state of that pin may be read into the cpu rather than the new state. when in doubt, it is better to sepa- rate these instructions with a nop or another instruction not accessing this i/o port. figure 5-16: successive i/o operation ;initial port settings:portb<7:4> inputs ; portb<3:0> outputs ;portb<7:6> have external pull-up and are ;not connected to other circuitry ; ; port latchport pins ---------- ---------- bcf status, rp0 ; bcf portb, 7 ;01pp pppp 11pp pppp bsf status, rp0 ; bcf trisb, 7 ;10pp pppp 11pp pppp bcf trisb, 6 ;10pp pppp 10pp pppp ; ;note that the user may have expected the ;pin values to be 00pp pppp. the 2nd bcf ;caused rb7 to be latched as the pin value ;(high). q1 q2 q3 q4 pc instruction fetched q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 pc + 1 pc pc + 2 pc + 3 movwf portb write to portb movf portb, w read to portb nop nop t pd execute movwf portb execute movf portb, w port pin sampled here execute nop note 1: this example shows write to portb followed by a read from portb. 2: data setup time = (0.25 t cy - t pd ) where t cy = instruction cycle and t pd = propagation delay of q1 cycle to output valid. therefore, at higher clock frequencies, a write followed by a read may be problematic.
? 2002 microchip technology inc. preliminary ds40044a-page 45 pic16f627a/628a/648a 6.0 timer0 module the timer0 module timer/counter has the following features:  8-bit timer/counter  read/write capabilities  8-bit software programmable prescaler  internal or external clock select  interrupt on overflow from ffh to 00h  edge select for external clock figure 6-1 is a simplified block diagram of the timer0 module. additional information is available in the picmicro? mid-range mcu family reference man- ual, ds33023. timer mode is selected by clearing the t0cs bit (option<5>). in timer mode, the tmr0 register value will increment every instruction cycle (without pres- caler). if the tmr0 register is written to, the increment is inhibited for the following two cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting the t0cs bit. in this mode the tmr0 register value will increment either on every rising or falling edge of pin ra4/t0cki. the incrementing edge is determined by the source edge (t0se) control bit (option<4>). clearing the t0se bit selects the rising edge. restrictions on the external clock input are discussed in detail in section 6.2. the prescaler is shared between the timer0 module and the watchdog timer. the prescaler assignment is controlled in software by the control bit psa (option<3>). clearing the psa bit will assign the prescaler to timer0. the prescaler is not readable or writable. when the prescaler is assigned to the timer0 module, prescale value of 1:2, 1:4,..., 1:256 are selectable. section 6.3 details the operation of the prescaler. 6.1 timer0 interrupt timer0 interrupt is generated when the tmr0 register timer/counter overflows from ffh to 00h. this overflow sets the t0if bit. the interrupt can be masked by clear- ing the t0ie bit (intcon<5>). the t0if bit (intcon<2>) must be cleared in software by the timer0 module interrupt service routine before re- enabling this interrupt. the timer0 interrupt cannot wake the processor from sleep since the timer is shut off during sleep. 6.2 using timer0 with external clock when an external clock input is used for timer0, it must meet certain requirements. the external clock requirement is due to internal phase clock (t osc ) synchronization. also, there is a delay in the actual incrementing of timer0 after synchronization. 6.2.1 external clock synchronization when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki with the internal phase clocks is accomplished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks (figure 6-1). therefore, it is necessary for t0cki to be high for at least 2t osc (and a small rc delay of 20 ns) and low for at least 2t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. when a prescaler is used, the external clock input is divided by the asynchronous ripple-counter type prescaler so that the prescaler output is symmetrical. for the external clock to meet the sampling requirement, the ripple-counter must be taken into account. therefore, it is necessary for t0cki to have a period of at least 4t osc (and a small rc delay of 40 ns) divided by the prescaler value. the only requirement on t0cki high and low time is that they do not violate the minimum pulse width requirement of 10 ns. refer to parameters 40, 41 and 42 in the electrical specification of the desired device. see table 17-9.
pic16f627a/628a/648a ds40044a-page 46 preliminary ? 2002 microchip technology inc. 6.3 timer0 prescaler an 8-bit counter is available as a prescaler for the timer0 module, or as a postscaler for the watchdog timer. a prescaler assignment for the timer0 module means that there is no postscaler for the watchdog timer, and vice-versa. the psa and ps2:ps0 bits (option<3:0>) determine the prescaler assignment and prescale ratio. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf 1, movwf 1, bsf 1, x....etc. ) will clear the pres- caler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. the prescaler is not readable or writable. figure 6-1: block diagram of the timer0/wdt t0cki t0se pin f osc /4 sync 2 cycles tmr0 reg 8-to-1mux watchdog timer psa wdt time out ps0 - ps2 8 . psa wdt enable bit data bus set flag bit t0if on overflow 8 psa note: t0se, t0cs, psa, ps0-ps2 are bits in the option register. t0cs wdt postscaler/ tmr0 prescaler 1 0 1 0 1 0 1 0 tmr1 clock source
? 2002 microchip technology inc. preliminary ds40044a-page 47 pic16f627a/628a/648a 6.3.1 switching prescaler assignment the prescaler assignment is fully under software control (i.e., it can be changed ?on the fly? during program execution). use the instruction sequences shown in example 6-1 when changing the prescaler assignment from timer0 to wdt, to avoid an unin- tended device reset. example 6-1: changing prescaler (timer0 wdt) to change prescaler from the wdt to the timer0 module, use the sequence shown in example 6-2. this precaution must be taken even if the wdt is disabled. example 6-2: changing prescaler (wdt timer0) table 6-1: registers associated with timer0 bcf status, rp0 ;skip if already in ;bank 0 clrwdt ;clear wdt clrf tmr0 ;clear tmr0 and ;prescaler bsf status, rp0 ;bank 1 movlw '00101111?b ;these 3 lines ;(5, 6, 7) movwf option_reg ;are required only ;if desired ps<2:0> ;are clrwdt ;000 or 001 movlw '00101xxx?b ;set postscaler to movwf option_reg ;desired wdt rate bcf status, rp0 ;return to bank 0 clrwdt ;clear wdt and ;prescaler bsf status, rp0 movlw b'xxxx0xxx' ;select tmr0, new ;prescale value and ;clock source movwf option_reg bcf status, rp0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 01h, 101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 81h, 181h option (2) rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: ? = unimplemented locations, read as ?0?, u = unchanged, x = unknown note 1: shaded bits are not used by timer0 module. 2: option is referred by option_reg in mplab ? .
pic16f627a/628a/648a ds40044a-page 48 preliminary ? 2002 microchip technology inc. 7.0 timer1 module the timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (tmr1h and tmr1l) which are readable and writable. the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow of the tmr1 register pair which latches the interrupt flag bit tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing the timer1 interrupt enable bit tmr1ie (pie1<0>). timer1 can operate in one of two modes:  as a timer  as a counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). in timer mode, the tmr1 register pair value incre- ments every instruction cycle. in counter mode, it increments on every rising edge of the external clock input. timer1 can be enabled/disabled by setting/clearing control bit tmr1on (t1con<0>). timer1 also has an internal ?reset input?. this reset can be generated by the ccp module (section 9.0). register 7-1 shows the timer1 control register. for the pic16f627a/628a/648a, when the timer1 oscillator is enabled (t1oscen is set), the rb7/t1osi and rb6/t1oso/t1cki pins become inputs. that is, the trisb<7:6> value is ignored. register 7-1: t1con: timer1 control register (address: 10h) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 t1ckps1:t1ckps0 : timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen : timer1 oscillator enable control bit 1 = oscillator is enabled 0 = oscillator is shut off (1) bit 2 t1sync : timer1 external clock input synchronization control bit tmr1cs = 1 1 = do not synchronize external clock input 0 = synchronize external clock input t mr1cs = 0 this bit is ignored. timer1 uses the internal clock when tmr1cs = 0. bit 1 tmr1cs : timer1 clock source select bit 1 = external clock from pin rb6/t1oso/t1cki (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on : timer1 on bit 1 = disables timer1 0 = stops timer1 note 1: the oscillator inverter and feedback resistor are turned off to eliminate power drain. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 49 pic16f627a/628a/648a 7.1 timer1 operation in timer mode timer mode is selected by clearing the tmr1cs (t1con<1>) bit. in this mode, the input clock to the timer is f osc /4. the synchronize control bit t1sync (t1con<2>) has no effect since the internal clock is always in sync. 7.2 timer1 operation in synchronized counter mode counter mode is selected by setting bit tmr1cs. in this mode the tmr1 register pair value increments on every rising edge of clock input on pin rb7/t1osi when bit t1oscen is set or pin rb6/t1oso/t1cki when bit t1oscen is cleared. if t1sync is cleared, then the external clock input is synchronized with internal phase clocks. the synchro- nization is done after the prescaler stage. the pres- caler stage is an asynchronous ripple-counter. in this configuration, during sleep mode, the tmr1 register pair value will not increment even if the exter- nal clock is present, since the synchronization circuit is shut off. the prescaler however will continue to incre- ment. 7.2.1 external clock input timing for synchronized counter mode when an external clock input is used for timer1 in syn- chronized counter mode, it must meet certain require- ments. the external clock requirement is due to internal phase clock (tosc) synchronization. also, there is a delay in the actual incrementing of the tmr1 reg- ister pair value after synchronization. when the prescaler is 1:1, the external clock input is the same as the prescaler output. the synchronization of t1cki with the internal phase clocks is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t1cki to be high for at least 2tosc (and a small rc delay of 20 ns) and low for at least 2tosc (and a small rc delay of 20 ns). refer to the appropri- ate electrical specifications, parameters 45, 46, and 47. when a prescaler other than 1:1 is used, the external clock input is divided by the asynchronous ripple- counter type prescaler so that the prescaler output is symmetrical. in order for the external clock to meet the sampling requirement, the ripple-counter must be taken into account. therefore, it is necessary for t1cki to have a period of at least 4tosc (and a small rc delay of 40 ns) divided by the prescaler value. the only requirement on t1cki high and low time is that they do not violate the minimum pulse width requirements of 10 ns). refer to the appropriate electrical specifications, parameters 45, 46, and 47. figure 7-1: timer1 block diagram tmr1h tmr1l t1osc t1sync tmr1cs t1ckps1:t1ckps0 sleep input t1oscen enable oscillator(1) f osc /4 internal clock tmr1on prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 rb6/t1oso/t1cki rb7/t1osi note 1: when the t1oscen bit is cleared, the inverter and feedback resistor are turned off. this eliminates power drain. set flag bit tmr1if on overflow tmr1
pic16f627a/628a/648a ds40044a-page 50 preliminary ? 2002 microchip technology inc. 7.3 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt on overflow, which will wake-up the processor. however, special precautions in soft- ware are needed to read/write the timer (section 7.3.2). 7.3.1 external clock input timing with unsynchronized clock if control bit t1sync is set, the timer will increment completely asynchronously. the input clock must meet certain minimum high and low time requirements. refer to table 17-9 in the electrical specifications section, timing parameters 45, 46, and 47. 7.3.2 reading and writing timer1 in asynchronous counter mode reading the tmr1h or tmr1l register while the timer is running, from an external asynchronous clock, will produce a valid read (taken care of in hardware). how- ever, the user should keep in mind that reading the 16- bit timer in two 8-bit values itself poses certain prob- lems since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write conten- tion may occur by writing to the timer registers while the register is incrementing. this may produce an unpre- dictable value in the timer register. reading the 16-bit value requires some care. example 7-1 is an example routine to read the 16-bit timer value. this is useful if the timer cannot be stopped. example 7-1: reading a 16-bit free- running timer note: in asynchronous counter mode, timer1 cannot be used as a time-base for capture or compare operations. ; all interrupts are disabled movf tmr1h, w ;read high byte movwf tmph ; movf tmr1l, w ;read low byte movwf tmpl ; movf tmr1h, w ;read high byte subwf tmph, w ;sub 1st read with ;2nd read btfsc status,z ;is result = 0 goto continue ;good 16-bit read ; ; tmr1l may have rolled over between the ; read of the high and low bytes. reading ; the high and low bytes now will read a good ; value. ; movf tmr1h, w ;read high byte movwf tmph ; movf tmr1l, w ;read low byte movwf tmpl ; ; re-enable the interrupts (if required) continue ;continue with your ;code
? 2002 microchip technology inc. preliminary ds40044a-page 51 pic16f627a/628a/648a 7.4 timer1 oscillator a crystal oscillator circuit is built in between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit t1oscen (t1con<3>). it will con- tinue to run during sleep. it is primarily intended for a 32.768 khz watch crystal. table 7-1 shows the capaci- tor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper oscillator start-up. table 7-1: capacitor selection for the timer1 oscillator 7.5 resetting timer1 using a ccp trigger output if the ccp1 module is configured in compare mode to generate a ?special event trigger? (ccp1m3:ccp1m0 = 1011 ), this signal will reset timer1. timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a spe- cial event trigger from ccp1, the write will take prece- dence. in this mode of operation, the ccprxh:ccprxl regis- ters pair effectively becomes the period register for timer1. 7.6 resetting timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por or any other reset except by the ccp1 special event triggers. t1con register is reset to 00h on a power-on reset or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 7.7 timer1 prescaler the prescaler counter is cleared on writes to the tmr1h or tmr1l registers. table 7-2: registers associated with timer1 as a timer/counter freq c1 c2 32.768 khz 15 pf 15 pf these values are for design guidance only. consult an826 (ds00826) for further information on crystal/capacitor selection. note: the special event triggers from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by the timer1 module.
pic16f627a/628a/648a ds40044a-page 52 preliminary ? 2002 microchip technology inc. 8.0 timer2 module timer2 is an 8-bit timer with a prescaler and a postscaler. it can be used as the pwm time-base for pwm mode of the ccp module. the tmr2 register is readable and writable, and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits t2ckps1:t2ckps0 (t2con<1:0>). the timer2 module has an 8-bit period register pr2. the tmr2 register value increments from 00h until it matches the pr2 register value and then resets to 00h on the next increment cycle. the pr2 register is a readable and writable register. the pr2 register is ini- tialized to ffh upon reset. the match output of timer2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a timer2 interrupt (latched in flag bit tmr2if, (pir1<1>)). timer2 can be shut off by clearing control bit tmr2on (t2con<2>) to minimize power consumption. register 8-1 shows the timer2 control register. 8.1 timer2 prescaler and postscaler the prescaler and postscaler counters are cleared when any of the following occurs:  a write to the tmr2 register  a write to the t2con register  any device reset (power-on reset, mclr reset, watchdog timer reset, or brown-out reset) the tmr2 register is not cleared when t2con is writ- ten. 8.2 tmr2 output the tmr2 output (before the postscaler) is fed to the synchronous serial port module which optionally uses it to generate shift clock. figure 8-1: timer2 block diagram comparator tmr2 sets flag tmr2 reg output reset postscaler prescaler pr2 reg 2 f osc /4 1:1 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if to t2ckps<1:0> toutps<3:0>
? 2002 microchip technology inc. preliminary ds40044a-page 53 pic16f627a/628a/648a register 8-1: t2con: timer2 control register (address: 12h) table 8-1: registers associated with timer2 as a timer/counter u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as '0' bit 6-3 toutps3:toutps0 : timer2 output postscale select bits 0000 = 1:1 postscale value 0001 = 1:2 postscale value    1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps1:t2ckps0 : timer2 clock prescale select bits 00 = 1:1 prescaler value 01 = 1:4 prescaler value 1x = 1:16 prescaler value legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 11h tmr2 timer2 modules register 0000 0000 0000 0000 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by the timer2 module.
pic16f627a/628a/648a ds40044a-page 54 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 55 pic16f627a/628a/648a 9.0 capture/compare/pwm (ccp) module the ccp (capture/compare/pwm) module contains a 16-bit register which can operate as a 16-bit capture register, as a 16-bit compare register or as a pwm master/slave duty cycle register. table 9-1 shows the timer resources of the ccp module modes. ccp1 module capture/compare/pwm register1 (ccpr1) is com- prised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. all are readable and writable. additional information on the ccp module is available in the picmicro? mid-range reference manual, (ds33023). table 9-1: ccp mode - timer resource register 9-1: ccp1con register (address: 17h) ccp mode timer resource capture compare pwm timer1 timer1 timer2 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 ccp1x:ccp1y : pwm least significant bits capture mode: unused compare mode: unused pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccprxl. bit 3-0 ccp1m3:ccp1m0 : ccpx mode select bits 0000 = capture/compare/pwm off (resets ccp1 module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit is set; ccp1 resets tmr1 11xx = pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 56 preliminary ? 2002 microchip technology inc. 9.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin rb3/ccp1. an event is defined as:  every falling edge  every rising edge  every 4th rising edge  every 16th rising edge an event is selected by control bits ccp1m3:ccp1m0 (ccp1con<3:0>). when a capture is made, the inter- rupt request flag bit ccp1if (pir1<2>) is set. it must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value will be lost. 9.1.1 ccp pin configuration in capture mode, the rb3/ccp1 pin should be config- ured as an input by setting the trisb<3> bit. figure 9-1: capture mode operation block diagram 9.1.2 timer1 mode selection timer1 must be running in timer mode or synchronized counter mode for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 9.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit ccp1if following any such change in operating mode. 9.1.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m3:ccp1m0. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore the first capture may be from a non-zero prescaler. example 9-1 shows the recom- mended method for switching between capture pres- calers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 9-1: changing between capture prescalers 9.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the rb3/ccp1 pin is:  driven high  driven low  remains unchanged the action on the pin is based on the value of control bits ccp1m3:ccp1m0 (ccp1con<3:0>). at the same time, interrupt flag bit ccp1if is set. figure 9-2: compare mode operation block diagram note: if the rb3/ccp1 is configured as an out- put, a write to the port can cause a capture condition. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> rb3/ccp1 prescaler 3 1, 4, 16 and edge detect pin clrf ccp1con ;turn ccp module off movlw new_capt_ps ;load the w reg with ; the new prescaler ; mode value and ccp on movwf ccp1con ;load ccp1con with this ; value ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic set flag bit ccp1if (pir1<2>) match rb3/ccp1 trisb<3> ccp1con<3:0> mode select output enable pin note: special event trigger will reset timer1, but not set interrupt flag bit tmr1if (pir1<0>)
? 2002 microchip technology inc. preliminary ds40044a-page 57 pic16f627a/628a/648a 9.2.1 ccp pin configuration the user must configure the rb3/ccp1 pin as an out- put by clearing the trisb<3> bit. 9.2.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 9.2.3 software interrupt mode when generate software interrupt is chosen the ccp1 pin is not affected. only a ccp interrupt is generated (if enabled). 9.2.4 special event trigger in this mode, an internal hardware trigger is generated which may be used to initiate an action. the special event trigger output of ccp1 resets the tmr1 register pair. this allows the ccpr1 register to effectively be a 16-bit programmable period register for timer1. table 9-2: registers associated with capture, compare, and timer1 note: clearing the ccp1con register will force the rb3/ccp1 compare output latch to the default low level. this is not the data latch. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 86h, 186h trisb portb data direction register 1111 1111 1111 1111 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by capture and timer1.
pic16f627a/628a/648a ds40044a-page 58 preliminary ? 2002 microchip technology inc. 9.3 pwm mode in pulse width modulation (pwm) mode, the ccp1 pin produces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with the portb data latch, the trisb<3> bit must be cleared to make the ccp1 pin an output. figure 9-3 shows a simplified block diagram of the ccp module in pwm mode. for a step by step procedure on how to set up the ccp module for pwm operation, see section 9.3.3. figure 9-3: simplified pwm block diagram a pwm output (figure 9-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (fre- quency = 1/period). figure 9-4: pwm output 9.3.1 pwm period the pwm period is specified by writing to the pr2 reg- ister. the pwm period can be calculated using the fol- lowing formula: pwm frequency is defined as 1 / [pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle:  tmr2 is cleared  the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is latched from ccpr1l into ccpr1h note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portb i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisb<3> rb3/ccp1 note 1: 8-bit timer is concatenated with 2-bit internal q clock or 2 bits of the prescaler to create 10-bit time-base. note: the timer2 postscaler (see section 8.0) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different fre- quency than the pwm output. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period pr 2 () 1 + [] 4 ?? = tosc tmr2 prescale ? value
? 2002 microchip technology inc. preliminary ds40044a-page 59 pic16f627a/628a/648a 9.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available: the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time: ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitch less pwm operation. when the ccpr1h and 2-bit latch match tmr2 con- catenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. maximum pwm resolution (bits) for a given pwm frequency: for an example pwm period and duty cycle calcula- tion, see the picmicro? mid-range reference man- ual (ds33023). 9.3.3 set-up for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 regis- ter. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the trisb<3> bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. table 9-3: example pwm frequencies and resolutions at 20 mhz table 9-4: registers associated with pwm and timer2 (ccpr1l:ccp1con<5:4>) tosc tmr2 prescale ?? value pwm duty cycle = note: if the pwm duty cycle value is longer than the pwm period the ccp1 pin will not be cleared. resolution log fosc fpwm tmr2 prescaler ------------------------------------------------------------- ?? ?? log(2) --------------------------------------------------------------------------- bits = pwm pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12 khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 1641111 pr2 value 0xff 0xff 0xff 0x3f 0x1f 0x17 maximum resolution (bits) 10 10 10 8 7 6.5 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 86h, 186h trisb portb data direction register 1111 1111 1111 1111 11h tmr2 timer2 modules register 0000 0000 0000 0000 92h pr2 timer2 modules period register 1111 1111 1111 1111 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 uuuu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by pwm and timer2.
pic16f627a/628a/648a ds40044a-page 60 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 61 pic16f627a/628a/648a 10.0 comparator module the comparator module contains two analog comparators. the inputs to the comparators are multiplexed with the ra0 through ra3 pins. the on- chip voltage reference (section 11.0) can also be an input to the comparators. the cmcon register, shown in register 10-1, controls the comparator input and output multiplexers. a block diagram of the comparator is shown in figure 10-1. register 10-1: cmcon register (address: 01fh) r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out : comparator 2 output when c2inv = 0: 1 = c2 v in + > c2 v in - 0 = c2 v in + < c2 v in - when c2inv = 1: 1 = c2 v in + < c2 v in - 0 = c2 v in + > c2 v in - bit 6 c1out : comparator 1 output when c1inv = 0: 1 = c1 v in + > c1 v in - 0 = c1 v in + < c1 v in - when c1inv = 1: 1 = c1 v in + < c1 v in - 0 = c1 v in + > c1 v in - bit 5 c2inv : comparator 2 output inversion 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv : comparator 1 output inversion 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis : comparator input switch when cm2:cm0: = 001 then: 1 = c1 v in - connects to ra3 0 = c1 v in - connects to ra0 when cm2:cm0 = 010 then: 1 = c1 v in - connects to ra3 c2 v in - connects to ra2 0 = c1 v in - connects to ra0 c2 v in - connects to ra1 bit 2-0 cm2:cm0 : comparator mode figure 10-1 shows the comparator modes and cm2:cm0 bit settings legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 62 preliminary ? 2002 microchip technology inc. 10.1 comparator configuration there are eight modes of operation for the comparators. the cmcon register is used to select the mode. figure 10-1 shows the eight possible modes. the trisa register controls the data direction of the comparator pins for each mode. if the compara- tor mode is changed, the comparator output level may not be valid for the specified mode change delay shown in table 17-2. figure 10-1: comparator i/o operating modes note 1: comparator interrupts should be disabled during a comparator mode change, other- wise a false interrupt may occur. 2: comparators can have an inverted out- put. see figure 10-3. c1 ra0/an0 v in - v in + ra3/an3/cmp1 comparators reset (por default value) a a cm2:cm0 = 000 c2 ra1/an1 v in - v in + ra2/an2/v ref a a c1 ra0/an0 v in - v in + ra3/an3/cmp1 two independent comparators a a cm2:cm0 = 100 c2 ra1/an1 v in - v in + ra2/an2/v ref a a c1 ra0/an0 v in - v in + ra3/an3/cmp1 two common reference comparators a d cm2:cm0 = 011 c2 ra1/an1 v in - v in + ra2/an2/v ref a a c1 ra0/an0 v in - v in + ra3/an3/cmp1 off (read as '0') one independent comparator d d cm2:cm0 = 101 c2 ra1/an1 v in - v in + ra2/an2/v ref a a c1 v in - v in + off (read as '0') comparators off d d cm2:cm0 = 111 c2 v in - v in + off (read as '0') d d c1 ra0/an0 v in - v in + ra3/an3/cmp1 four inputs multiplexed to two comparators a a cm2:cm0 = 010 c2 ra1/an1 v in - v in + ra2/an2/v ref a a from v ref cis = 0 cis = 1 cis = 0 cis = 1 c1 ra0/an0 v in - v in + ra3/an3/cmp1 two common reference comparators with outputs a d cm2:cm0 = 110 c2 ra1/an1 v in - v in + ra2/an2/v ref a a open drain a = analog input, port reads zeros always. d = digital input. cis (cmcon<3>) is the comparator input switch. ra4/t0cki/cmp2 c1 ra0/an0 v in - v in + ra3/an3/cmp1 three inputs multiplexed to two comparators a a cm2:cm0 = 001 c2 ra1/an1 v in - v in + ra2/an2/v ref a a cis = 0 cis = 1 v ss v ss ra0/an0 ra3/an3/cmp1 ra1/an1 ra2/an2/v ref module c1v out c2v out c1v out c2v out off (read as '0') off (read as '0') c2v out c1v out c2v out c1v out c2v out c1v out c2v out
? 2002 microchip technology inc. preliminary ds40044a-page 63 pic16f627a/628a/648a the code example in example 10-1 depicts the steps required to configure the comparator module. ra3 and ra4 are configured as digital output. ra0 and ra1 are configured as the v- inputs and ra2 as the v+ input to both comparators. example 10-1: initializing comparator module 10.2 comparator operation a single comparator is shown in figure 10-2 along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 10-2 represent the uncertainty due to input offsets and response time. see table 17-2 for common mode voltage. 10.3 comparator reference an external or internal reference signal may be used depending on the comparator operating mode. the analog signal that is present at v in - is compared to the signal at v in +, and the digital output of the comparator is adjusted accordingly (figure 10-2). figure 10-2: single comparator 10.3.1 external reference signal when external voltage references are used, the comparator module can be configured to have the comparators operate from the same or different reference sources. however, threshold detector applications may require the same reference. the reference signal must be between v ss and v dd , and can be applied to either pin of the comparator(s). 10.3.2 internal reference signal the comparator module also allows the selection of an internally generated voltage reference for the comparators. section 11.0, voltage reference manual, contains a detailed description of the voltage refer- ence module that provides this signal. the internal ref- erence signal is used when the comparators are in mode cm<2:0>=010 (figure 10-1). in this mode, the internal voltage reference is applied to the v in + pin of both comparators. 10.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output is to have a valid level. if the internal reference is changed, the maximum delay of the inter- nal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used (table 17-2 ). flag_reg equ 0x20 clrf flag_reg ;init flag register clrf porta ;init porta movf cmcon, w ;load comparator bits andlw 0xc0 ;mask comparator bits iorwf flag_reg,f ;store bits in flag register movlw 0x03 ;init comparator mode movwf cmcon ;cm<2:0> = 011 bsf status,rp0 ;select bank1 movlw 0x07 ;initialize data direction movwf trisa ;set ra<2:0> as inputs ;ra<4:3> as outputs ;trisa<7:5> always read ?0? bcf status,rp0 ;select bank 0 call delay10 ;10 s delay movf cmcon,f ;read cmcon to end change ;condition bcf pir1,cmif ;clear pending interrupts bsf status,rp0 ;select bank 1 bsf pie1,cmie ;enable comparator interrupts bcf status,rp0 ;select bank 0 bsf intcon,peie ;enable peripheral interrupts bsf intcon,gie ;global interrupt enable ? + vin+ vin- result result v in - v in +
pic16f627a/628a/648a ds40044a-page 64 preliminary ? 2002 microchip technology inc. 10.5 comparator outputs the comparator outputs are read through the cmcon register. these bits are read only. the comparator outputs may also be directly output to the ra3 and ra4 i/o pins. when the cm<2:0> = 110 or 001, multiplexors in the output path of the ra3 and ra4/t0ck1 pins will switch and the output of each pin will be the unsynchro- nized output of the comparator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 10-3 shows the comparator output block diagram. the trisa bits will still function as an output enable/ disable for the ra3 and ra4/t0ck1 pins while in this mode. figure 10-3: modified comparator output block diagram note 1: when reading the port register, all pins configured as analog inputs will read as a ?0?. pins configured as digital inputs will convert an analog input, according to the schmitt trigger input specification. 2: analog levels on any pin that is defined as a digital input may cause the input buffer to consume more current than is speci- fied. d q en to ra3 or ra4/t0ck1 pin set cmif bit d q en cl reset from other comparator to d a ta b u s cnv out cni nv q1 rd cmcon cmcon<7:6> q3
? 2002 microchip technology inc. preliminary ds40044a-page 65 pic16f627a/628a/648a 10.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:6>, to determine the actual change that has occurred. the cmif bit, pir1<6>, is the comparator interrupt flag. the cmif bit must be reset by clearing ?0?. since it is also possible to write a '1' to this register, a simulated interrupt may be initiated. the cmie bit (pie1<6>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any write or read of cmcon. this will end the mismatch condition. b) clear flag bit cmif. a mismatch condition will continue to set flag bit cmif. reading cmcon will end the mismatch condition and allow flag bit cmif to be cleared. 10.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode when enabled. while the comparator is powered-up, higher sleep currents than shown in the power-down current specification will occur. each comparator that is operational will consume additional current as shown in the comparator specifications. to minimize power consumption while in sleep mode, turn off the comparators, cm<2:0> = 111, before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 10.8 effects of a reset a device reset forces the cmcon register to its reset state. this forces the comparator module to be in the comparator reset mode, cm2:cm0 = 000. this ensures that all potential inputs are analog inputs. device current is minimized when analog inputs are present at reset time. the comparators will be powered-down during the reset interval. 10.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 10-4. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. note: if a change in the cmcon register (c1out or c2out) should occur when a read operation is being executed (start of the q2 cycle), then the cmif (pir1<6>) interrupt flag may not get set.
pic16f627a/628a/648a ds40044a-page 66 preliminary ? 2002 microchip technology inc. figure 10-4: analog input mode table 10-1: registers associated with comparator module address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 1fh cmcon c2out c1out c2inv c1nv cis cm2 cm1 cm0 0000 0000 0000 0000 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ?0? va r s < 10 k a in c pin 5pf v dd v t = 0.6 v v t = 0.6 v r ic i leakage 500 na v ss legend c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin r ic = interconnect resistance r s = source impedance va = analog voltage
? 2002 microchip technology inc. preliminary ds40044a-page 67 pic16f627a/628a/648a 11.0 voltage reference module the voltage reference is a 16-tap resistor ladder network that provides a selectable voltage reference. the resistor ladder is segmented to provide two ranges of v ref values and has a power-down function to conserve power when the reference is not being used. the vrcon register controls the operation of the reference as shown in figure 11-1. the block diagram is given in figure 11-1. 11.1 voltage reference configuration the voltage reference can output 16 distinct voltage levels for each range. the equations used to calculate the output of the voltage reference are as follows: if v rr = 1: if v rr = 0: the setting time of the voltage reference must be considered when changing the v ref output (table 17-3). example 11-1 demonstrates how voltage reference is configured for an output voltage of 1.25v with v dd = 5.0v. register 11-1: vrcon register (address: 9fh) figure 11-1: voltage reference block diagram v ref v r <3:0> 24 --------------------- - v dd = v ref v dd 1 4 -- - ?? ?? v r <3:0> 32 --------------------- - +v dd = r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 v ren v roe v rr ?v r 3v r 2v r 1v r 0 bit 7 bit 0 bit 7 v ren : v ref enable 1 = v ref circuit powered on 0 = v ref circuit powered down, no i dd drain bit 6 v roe : v ref output enable 1 = v ref is output on ra2 pin 0 = v ref is disconnected from ra2 pin bit 5 v rr : v ref range selection 1 = low range 0 = high range bit 4 unimplemented: read as '0' bit 3-0 v r <3:0> : v ref value selection 0 v r [3:0] 15 when v rr = 1: v ref = (v r <3:0>/ 24) * v dd when v rr = 0: v ref = 1/4 * v dd + (v r <3:0>/ 32) * v dd legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: r is defined in table 17-3. v rr 8r v r 3 v r 0 (from vrcon<3:0>) 16-1 analog mux 8r r r r r v ren v ref 16 stages v dd v ss v ss
pic16f627a/628a/648a ds40044a-page 68 preliminary ? 2002 microchip technology inc. example 11-1: voltage reference configuration 11.2 voltage reference accuracy/error the full range of v ss to v dd cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 11-1) keep v ref from approaching v ss or v dd . the voltage reference is v dd derived and therefore, the v ref output changes with fluctuations in v dd . the tested absolute accuracy of the voltage reference can be found in table 17-3. 11.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time out, the contents of the vrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 11.4 effects of a reset a device reset disables the voltage reference by clearing bit v ren (vrcon<7>). this reset also disconnects the reference from the ra2 pin by clearing bit v roe (vrcon<6>) and selects the high voltage range by clearing bit v rr (vrcon<5>). the v ref value select bits, vrcon<3:0>, are also cleared. 11.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra2 pin if the trisa<2> bit is set and the v roe bit, vrcon<6>, is set. enabling the voltage reference output onto the ra2 pin with an input signal present will increase current consumption. connecting ra2 as a digital output with v ref enabled will also increase current consumption. the ra2 pin can be used as a simple d/a output with limited drive capability. due to the limited drive capability, a buffer must be used in conjunction with the voltage reference output for external connections to v ref . figure 11-2 shows an example buffering technique. figure 11-2: voltage reference output buffer example table 11-1: registers associated with voltage reference movlw 0x02 ;4 inputs muxed movwf cmcon ;to 2 comps. bsf status,rp0 ;go to bank 1 movlw 0x07 ;ra3-ra0 are movwf trisa ;outputs movlw 0xa6 ;enable v ref movwf vrcon ;low range set v r <3:0>=6 bcf status,rp0 ;go to bank 0 call delay10 ;10 s delay address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 9fh vrcon vren vroe vrr ?vr3vr2vr1vr0 000- 0000 000- 0000 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 note: ? = unimplemented, read as ?0?. note 1: r is dependent upon the voltage reference configuration vrcon<3:0> and vrcon<5>. v ref module r (1) voltage reference output impedance ra2 v ref output + opamp
? 2002 microchip technology inc. preliminary ds40044a-page 69 pic16f627a/628a/648a 12.0 universal synchronous asynchronous receiver transmitter (usart) module the universal synchronous asynchronous receiver transmitter (usart) is also known as a serial com- munications interface or sci. the usart can be con- figured as a full-duplex asynchronous system that can communicate with peripheral devices such as crt ter- minals and personal computers, or it can be configured as a half-duplex synchronous system that can commu- nicate with peripheral devices such as a/d or d/a inte- grated circuits, serial eeproms, etc. the usart can be configured in the following modes:  asynchronous (full-duplex)  synchronous - master (half-duplex)  synchronous - slave (half-duplex) bit spen (rcsta<7>), and bits trisb<2:1>, have to be set in order to configure pins rb2/tx/ck and rb1/ rx/dt as the universal synchronous asynchronous receiver transmitter. register 12-1 shows the transmit status and control register (txsta) and register 12-2 shows the receive status and control register (rcsta). register 12-1: txsta: transmit status and control register (address: 98h) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync ? brgh trmt tx9d bit 7 bit 0 bit 7 csrc : clock source select bit asynchronous mode don?t care synchronous mode 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9 : 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen : transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync : usart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented: read as '0' bit 2 brgh : high baud rate select bit asynchronous mode 1 = high speed 0 = low speed synchronous mode unused in this mode bit 1 trmt : transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d : 9th bit of transmit data. can be parity bit. note: sren/cren overrides txen in sync mode. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 70 preliminary ? 2002 microchip technology inc. register 12-2: rcsta: receive status and control register (address: 18h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren aden ferr oerr rx9d bit 7 bit 0 bit 7 spen : serial port enable bit (configures rb1/rx/dt and rb2/tx/ck pins as serial port pins when bits trisb<2:1> are set) 1 = serial port enabled 0 = serial port disabled bit 6 rx9 : 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren : single receive enable bit asynchronous mode : don?t care synchronous mode - master : 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode - slave : unused in this mode bit 4 cren : continuous receive enable bit asynchronous mode : 1 = enables continuous receive 0 = disables continuous receive synchronous mode : 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 aden: address detect enable bit asynchronous mode 9-bit (rx9 = 1) : 1 = enables address detection, enable interrupt and load of the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received, and ninth bit can be used as parity bit asynchronous mode 8-bit (rx9=0) : unused in this mode synchronous mode unused in this mode bit 2 ferr : framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr : overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d : 9th bit of received data (can be parity bit) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 71 pic16f627a/628a/648a 12.1 usart baud rate generator (brg) the brg supports both the asynchronous and syn- chronous modes of the usart. it is a dedicated 8-bit baud rate generator. the spbrg register controls the period of a free running 8-bit timer. in asynchronous mode bit brgh (txsta<2>) also controls the baud rate. in synchronous mode bit brgh is ignored. table 12-1 shows the formula for computation of the baud rate for different usart modes, which only apply in master mode (internal clock). given the desired baud rate and f osc , the nearest integer value for the spbrg register can be calculated using the formula in table 12-1. from this, the error in baud rate can be determined. example 12-1 shows the calculation of the baud rate error for the following conditions: f osc = 16 mhz desired baud rate = 9600 brgh = 0 sync = 0 example 12-1: calculating baud rate error it may be advantageous to use the high baud rate (brgh = 1) even for slower baud clocks. this is because the f osc /(16(x + 1)) equation can reduce the baud rate error in some cases. writing a new value to the spbrg register, causes the brg timer to be reset (or cleared), this ensures the brg does not wait for a timer overflow before output- ting the new baud rate. table 12-1: baud rate formula table 12-2: registers associated with baud rate generator desired baud rate fosc 64 x 1 + () ---------------------- - = 9600 16000000 64 x 1 + () ----------------------- - = x 25.042 = calculated baud rate 16000000 64 25 1 + () -------------------------- 9615 == error (calculated baud rate - desired baud rate) desired baud rate ---------------------------------------------------------------------------------------------------------- = = 9615 9600 ? 9600 ----------------------------- - 0.16% = sync brgh = 0 (low speed) brgh = 1 (high speed) 0 1 (asynchronous) baud rate = f osc /(64(x+1)) (synchronous) baud rate = f osc /(4(x+1)) baud rate= f osc /(16(x+1)) na legend: x = value in spbrg (0 to 255) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as '0'. shaded cells are not used by the brg.
pic16f627a/628a/648a ds40044a-page 72 preliminary ? 2002 microchip technology inc. table 12-3: baud rates for synchronous mode baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3na? ?na? ?na? ? 1.2na? ?na? ?na? ? 2.4na? ?na? ?na? ? 9.6 na ? ? na ? ? 9.766 +1.73% 255 19.2 19.53 +1.73% 255 19.23 +0.16% 207 19.23 +0.16% 129 76.8 76.92 +0.16% 64 76.92 +0.16% 51 75.76 -1.36% 32 96 96.15 +0.16% 51 95.24 -0.79% 41 96.15 +0.16% 25 300 294.1 -1.96 16 307.69 +2.56% 12 312.5 +4.17% 7 500 500 0 9 500 0 7 500 0 4 high 5000 ? 0 4000 ? 0 2500 ? 0 low 19.53 ? 255 15.625 ? 255 9.766 ? 255 baud rate (k) f osc = 7.15909 mhz spbrg value (decimal) 5.0688 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3na? ?na? ?na? ? 1.2na? ?na? ?na? ? 2.4na? ?na? ?na? ? 9.6 9.622 +0.23% 185 9.6 0 131 9.615 +0.16% 103 19.2 19.24 +0.23% 92 19.2 0 65 19.231 +0.16% 51 76.8 77.82 +1.32 22 79.2 +3.13% 15 75.923 +0.16% 12 96 94.20 -1.88 18 97.48 +1.54% 12 1000 +4.17% 9 300 298.3 -0.57 5 316.8 5.60% 3 na ? ? 500 na ? ? na ? ?na? ? high 1789.8 ? 0 1267 ? 0 100 ? 0 low 6.991 ? 255 4.950 ? 255 3.906 ? 255 baud rate (k) f osc = 3.579545 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 na ? ? na ? ? 0.303 +1.14% 26 1.2 na ? ? 1.202 +0.16% 207 1.170 -2.48% 6 2.4 na ? ? 2.404 +0.16% 103 na ?? 9.6 9.622 +0.23% 92 9.615 +0.16% 25 na ? ? 19.2 19.04 -0.83% 46 19.24 +0.16% 12 na ? ? 76.8 74.57 -2.90% 11 83.34 +8.51% 2 na ? ? 96 99.43 +3.57% 8 na ?? na ? ? 300 298.3 0.57% 2 na ? ? na ? ? 500 na ? ?na? ? ? ? high 894.9 ? 0 250 ? 0 8.192 ? 0 low 3.496 ? 255 0.9766 ? 255 0.032 ? 255
? 2002 microchip technology inc. preliminary ds40044a-page 73 pic16f627a/628a/648a table 12-4: baud rates for asynchronous mode (brgh = 0) baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3na??na ??na ?? 1.2 1.221 +1.73% 255 1.202 +0.16% 207 1.202 +0.16% 129 2.4 2.404 +0.16% 129 2.404 +0.16% 103 2.404 +0.16% 64 9.6 9.469 -1.36% 32 9.615 +0.16% 25 9.766 +1.73% 15 19.2 19.53 +1.73% 15 19.23 +0.16% 12 19.53 +1.73v 7 76.8 78.13 +1.73% 3 83.33 +8.51% 2 78.13 +1.73% 1 96 104.2 +8.51% 2 na ? ? na ? ? 300 312.5 +4.17% 0 na ? ? na ? ? 500na??na??na?? high 312.5 ? 0 250 ? 0 156.3 ? 0 low 1.221 ? 255 0.977 ? 255 0.6104 ? 255 baud rate (k) f osc = 7.15909 mhz spbrg value (decimal) 5.0688 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 na ? ? 0.31 +3.13% 255 0.3005 -0.17% 207 1.2 1.203 +0.23% 92 1.2 0 65 1.202 +1.67% 51 2.4 2.380 -0.83% 46 2.4 0 32 2.404 +1.67% 25 9.6 9.322 -2.90% 11 9.9 +3.13% 7 na ? ? 19.2 18.64 -2.90% 5 19.8 +3.13% 3 na ? ? 76.8 na ? ? 79.2 +3.13% 0 na ? ? 96na??na??na?? 300na??na??na?? 500na??na??na?? high 111.9 ? 0 79.2 ? 0 62.500 ? 0 low 0.437 ? 255 0.3094 ? 255 3.906 ? 255 baud rate (k) f osc = 3.579545 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 0.301 +0.23% 185 0.300 +0.16% 51 0.256 -14.67% 1 1.2 1.190 -0.83% 46 1.202 +0.16% 12 na ? ? 2.4 2.432 +1.32% 22 2.232 -6.99% 6 na ? ? 9.6 9.322 -2.90% 5 na ? ? na ? ? 19.2 18.64 -2.90% 2 na ? ? na ? ? 76.8na??na??na?? 96na??na??na?? 300na??na??na?? 500na??na??na?? high 55.93 ? 0 15.63 ? 0 0.512 ? 0 low 0.2185 ? 255 0.0610 ? 255 0.0020 ? 255
pic16f627a/628a/648a ds40044a-page 74 preliminary ? 2002 microchip technology inc. table 12-5: baud rates for asynchronous mode (brgh = 1) baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9.615 +0.16% 129 9.615 +0.16% 103 9.615 +0.16% 64 19200 19.230 +0.16% 64 19.230 +0.16% 51 18.939 -1.36% 32 38400 37.878 -1.36% 32 38.461 +0.16% 25 39.062 +1.7% 15 57600 56.818 -1.36% 21 58.823 +2.12% 16 56.818 -1.36% 10 115200 113.636 -1.36% 10 111.111 -3.55% 8 125 +8.51% 4 250000 250 0 4 250 0 3 na ? ? 625000 625 0 1 na ? ? 625 0 0 1250000 1250 0 0 na ? ? na ? ? baud rate (k) f osc = 7.16 mhz spbrg value (decimal) 5.068 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9.520 -0.83% 46 9598.485 0.016% 32 9615.385 0.160% 25 19200 19.454 +1.32% 22 18632.35 -2.956% 16 19230.77 0.160% 12 38400 37.286 -2.90% 11 39593.75 3.109% 7 35714.29 -6.994% 6 57600 55.930 -2.90% 7 52791.67 -8.348% 5 62500 8.507% 3 115200 111.860 -2.90% 3 105583.3 -8.348% 2 125000 8.507% 1 250000 na ? ? 316750 26.700% 0 250000 0.000% 0 625000 na ? ? na ? ? na ? ? 1250000 na ? ? na ? ? na ? ? baud rate (k) f osc = 3.579 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9725.543 1.308% 22 8.928 -6.994% 6 na na na 19200 18640.63 -2.913% 11 20833.3 8.507% 2 na na na 38400 37281.25 -2.913% 5 31250 -18.620% 1 na na na 57600 55921.88 -2.913% 3 62500 +8.507 0 na na na 115200 111243.8 -2.913% 1 na ? ? na na na 250000 223687.5 -10.525% 0 na ? ? na na na 625000 na ? ? na ? ? na na na 1250000 na ? ? na ? ? na na na
? 2002 microchip technology inc. preliminary ds40044a-page 75 pic16f627a/628a/648a the data on the rb1/rx/dt pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. if bit brgh (txsta<2>) is clear (i.e., at the low baud rates), the sampling is done on the seventh, eighth and ninth fall- ing edges of a x16 clock (figure 12-3). if bit brgh is set (i.e., at the high baud rates), the sampling is done on the 3 clock edges preceding the second rising edge after the first falling edge of a x4 clock (figure 12-4 and figure 12-5). figure 12-1: rx pin sampling scheme. brgh = 0 figure 12-2: rx pin sampling scheme, brgh = 1 figure 12-3: rx pin sampling scheme, brgh = 1 rx baud clk x16 clk start bit bit0 samples 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 baud clk for all but start bit (rb1/rx/dt pin) rx pin baud clk x4 clk q2, q4 clk start bit bit0 bit1 first falling edge after rx pin goes low second rising edge samples samples samples 1234123412 rx pin baud clk x4 clk q2, q4 clk start bit bit0 first falling edge after rx pin goes low second rising edge samples 12 3 4 baud clk for all but start bit
pic16f627a/628a/648a ds40044a-page 76 preliminary ? 2002 microchip technology inc. figure 12-4: rx pin sampling scheme, brgh = 0 or brgh = 1 12.2 usart asynchronous mode in this mode, the usart uses standard non-return-to- zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8-bit. a dedicated 8-bit baud rate generator is used to derive baud rate frequencies from the oscillator. the usart transmits and receives the lsb first. the usart?s transmitter and receiver are functionally inde- pendent but use the same data format and baud rate. the baud rate generator produces a clock either x16 or x64 of the bit shift rate, depending on bit brgh (txsta<2>). parity is not supported by the hardware, but can be implemented in software (and stored as the ninth data bit). asynchronous mode is stopped during sleep. asynchronous mode is selected by clearing bit sync (txsta<4>). the usart asynchronous module consists of the fol- lowing important elements:  baud rate generator  sampling circuit  asynchronous transmitter  asynchronous receiver 12.2.1 usart asynchronous transmitter the usart transmitter block diagram is shown in figure 12-5. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit txif (pir1<4>) is set. this interrupt can be enabled/disabled by setting/clearing enable bit txie ( pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicated the status of the txreg register, another bit trmt (txsta<1>) shows the status of the tsr register. status bit trmt is a read only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to deter- mine if the tsr register is empty. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data and the baud rate generator (brg) has produced a shift clock (figure 12-5). the transmission can also be started by first loading the txreg register and then setting enable bit txen. normally when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate trans- fer to tsr resulting in an empty txreg. a back-to- back transfer is thus possible (figure 12-7). clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the trans- mitter. as a result the rb2/tx/ck pin will revert to hi- impedance. in order to select 9-bit transmission, transmit bit tx9 (txsta<6>) should be set and the ninth bit should be written to tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg reg- ister. this is because a data write to the txreg regis- ter can result in an immediate transfer of the data to the tsr register (if the tsr is empty). in such a case, an incorrect ninth data bit maybe loaded in the tsr regis- ter. rx baud clk x16 clk start bit bit0 samples 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 baud clk for all but start bit (rb1/rx/dt pin) note 1: the tsr register is not mapped in data memory so it is not available to the user. 2: flag bit txif is set when enable bit txen is set.
? 2002 microchip technology inc. preliminary ds40044a-page 77 pic16f627a/628a/648a figure 12-5: usart transmit block diagram follow these steps when setting up an asynchronous transmission: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. (section 12.1) 3. enable the asynchronous serial port by clearing bit sync and setting bit spen. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set transmit bit tx9. 6. enable the transmission by setting bit txen, which will also set bit txif. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. load data to the txreg register (starts trans- mission). figure 12-6: asynchronous transmission txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rb2/tx/ck pin pin buffer and control 8 2 2 2 word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rb2/tx/ck (pin) txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag)
pic16f627a/628a/648a ds40044a-page 78 preliminary ? 2002 microchip technology inc. figure 12-7: asynchronous transmission (back to back) table 12-6: registers associated with asynchronous transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded cells are not used for asynchronous transmission. transmit shift reg. write to txreg brg output (shift clock) rb2/tx/ck (pin) txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 . note: this timing diagram shows two consecutive transmissions.
? 2002 microchip technology inc. preliminary ds40044a-page 79 pic16f627a/628a/648a 12.2.2 usart asynchronous receiver the receiver block diagram is shown in figure 12-8. the data is received on the rb1/rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter oper- ates at the bit rate or at f osc . when asynchronous mode is selected, reception is enabled by setting bit cren (rcsta<4>). the heart of the receiver is the receive (serial) shift reg- ister (rsr). after sampling the stop bit, the received data in the rsr is transferred to the rcreg register (if it is empty). if the transfer is complete, flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/ disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read-only bit, which is cleared by the hardware. it is cleared when the rcreg register has been read and is empty. the rcreg is a double buffered register, (i.e., it is a two deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte begin shifting to the rsr register. on the detection of the stop bit of the third byte, if the rcreg register is still full then overrun error bit oerr (rcsta<1>) will be set. the word in the rsr will be lost. the rcreg reg- ister can be read twice to retrieve the two bytes in the fifo. overrun bit oerr has to be cleared in software. this is done by resetting the receive logic (cren is cleared and then set). if bit oerr is set, transfers from the rsr register to the rcreg register are inhibited, so it is essential to clear error bit oerr if it is set. fram- ing error bit ferr (rcsta<2>) is set if a stop bit is detected as clear. bit ferr and the 9th receive bit are buffered the same way as the receive data. reading the rcreg, will load bits rx9d and ferr with new values, therefore it is essential for the user to read the rcsta register before reading rcreg register in order not to lose the old ferr and rx9d information. figure 12-8: usart receive block diagram x64 baud rate clk spbrg baud rate generator rb1/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 3 64 3 16 or stop start (8) 7 1 0 rx9 2 2 2 rx9 aden rx9 aden rsr<8> enable load of receive buffer 8 8 rcreg register rx9d
pic16f627a/628a/648a ds40044a-page 80 preliminary ? 2002 microchip technology inc. figure 12-9: asynchronous reception with address detect figure 12-10: asynchronous reception with address byte first figure 12-11: asynchronous reception with address byte first followed by valid data byte start bit bit1 bit0 bit8 bit0 stop bit start bit bit8 stop bit rb1/rx/dt (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcreg rcif (interrupt flag) word 1 rcreg bit8 = 0, data byte bit8 = 1, address byte aden = 1 (address match enable) '1' '1' note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because aden = 1 and bit 8 = 0. start bit bit1 bit0 bit8 bit0 stop bit start bit bit8 stop bit rb1/rx/dt (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) word 1 rcreg bit8 = 1, address byte bit8 = 0, data byte aden = 1 (address match enable) '1' '1' note: this timing diagram shows an address byte followed by an data byte. the data byte is not read into the rcreg (receive buffer) because aden was not updated (still = 1) and bit 8 = 0. start bit bit1 bit0 bit8 bit0 stop bit start bit bit8 stop bit rb1/rx/dt (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) word 2 rcreg bit8 = 1, address byte bit8 = 0, data byte aden (address match enable) word 1 rcreg note: this timing diagram shows an address byte followed by an data byte. the data byte is read into the rcreg (receive buffer) because aden was updated after an address match, and was cleared to a ?0?, so the contents of the receive shift register (rsr) are read into the receive buffer regardless of the value of bit 8.
? 2002 microchip technology inc. preliminary ds40044a-page 81 pic16f627a/628a/648a follow these steps when setting up an asynchronous reception: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. (section 12.1). 3. enable the asynchronous serial port by clearing bit sync, and setting bit spen. 4. if interrupts are desired, then set enable bit rcie. 5. if 9-bit reception is desired, then set bit rx9. 6. enable the reception by setting bit cren. 7. flag bit rcif will be set when reception is com- plete and an interrupt will be generated if enable bit rcie was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing enable bit cren. table 12-7: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data registe r 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded cells are not used for asynchronous reception.
pic16f627a/628a/648a ds40044a-page 82 preliminary ? 2002 microchip technology inc. 12.3 usart address detect function 12.3.1 usart 9-bit receiver with address detect when the rx9 bit is set in the rcsta register, 9 bits are received and the ninth bit is placed in the rx9d bit of the rcsta register. the usart module has a spe- cial provision for multi-processor communication. mul- tiprocessor communication is enabled by setting the aden bit (rcsta<3>) along with the rx9 bit. the port is now programmed such that when the last bit is received, the contents of the receive shift register (rsr) are transferred to the receive buffer, the ninth bit of the rsr (rsr<8>) is transferred to rx9d, and the receive interrupt is set if and only if rsr<8> = 1. this feature can be used in a multi-processor system as fol- lows: a master processor intends to transmit a block of data to one of many slaves. it must first send out an address byte that identifies the target slave. an address byte is identified by setting the ninth bit (rsr<8>) to a '1' (instead of a '0' for a data byte). if the aden and rx9 bits are set in the slave?s rcsta register, enabling mul- tiprocessor communication, all data bytes will be ignored. however, if the ninth received bit is equal to a ?1?, indicating that the received byte is an address, the slave will be interrupted and the contents of the rsr register will be transferred into the receive buffer. this allows the slave to be interrupted only by addresses, so that the slave can examine the received byte to see if it is being addressed. the addressed slave will then clear its aden bit and prepare to receive data bytes from the master. when aden is enabled (='1'), all data bytes are ignored. following the stop bit, the data will not be loaded into the receive buffer, and no interrupt will occur. if another byte is shifted into the rsr register, the previous data byte will be lost. the aden bit will only take effect when the receiver is configured in 9-bit mode (rx9 = '1'). when aden is disabled (='0'), all data bytes are received and the 9th bit can be used as the parity bit. the receive block diagram is shown in figure 12-8. reception is enabled by setting bit cren (rcsta<4>). 12.3.1.1 setting up 9-bit mode with address detect follow these steps when setting up asynchronous reception with address detect enabled: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. 3. enable asynchronous communication by setting or clearing bit sync and setting bit spen. 4. if interrupts are desired, then set enable bit rcie. 5. set bit rx9 to enable 9-bit reception. 6. set aden to enable address detect. 7. enable the reception by setting enable bit cren or sren. 8. flag bit rcif will be set when reception is com- plete, and an interrupt will be generated if enable bit rcie was set. 9. read the 8-bit received data by reading the rcreg register to determine if the device is being addressed. 10. if any error occurred, clear the error by clearing enable bit cren if it was already set. 11. if the device has been addressed (rsr<8> = ?1? with address match enabled), clear the aden and rcif bits to allow data bytes and address bytes to be read into the receive buffer and inter- rupt the cpu. table 12-8: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded cells are not used for asynchronous reception.
? 2002 microchip technology inc. preliminary ds40044a-page 83 pic16f627a/628a/648a 12.4 usart synchronous master mode in synchronous master mode, the data is transmitted in a half-duplex manner, (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition enable bit spen (rcsta<7>) is set in order to configure the rb2/tx/ck and rb1/rx/dt i/o pins to ck (clock) and dt (data) lines respectively. the master mode indicates that the processor transmits the master clock on the ck line. the master mode is entered by setting bit csrc (txsta<7>). 12.4.1 usart synchronous master transmission the usart transmitter block diagram is shown in figure 12-5. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one tcycle), the txreg is empty and inter- rupt bit, txif (pir1<4>) is set. the interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit trmt (txsta<1>) shows the status of the tsr register. trmt is a read only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr reg- ister is empty. the tsr is not mapped in data memory so it is not available to the user. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data. the first data bit will be shifted out on the next available rising edge of the clock on the ck line. data out is sta- ble around the falling edge of the synchronous clock (figure 12-12). the transmission can also be started by first loading the txreg register and then setting bit txen (figure 12-13). this is advantageous when slow baud rates are selected, since the brg is kept in reset when bits txen, cren, and sren are clear. setting enable bit txen will start the brg, creating a shift clock immediately. normally when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr resulting in an empty txreg. back-to-back transfers are possible. clearing enable bit txen, during a transmission, will cause the transmission to be aborted and will reset the transmitter. the dt and ck pins will revert to hi- impedance. if either bit cren or bit sren is set, dur- ing a transmission, the transmission is aborted and the dt pin reverts to a hi-impedance state (for a reception). the ck pin will remain an output if bit csrc is set (internal clock). the transmitter logic however is not reset although it is disconnected from the pins. in order to reset the transmitter, the user has to clear bit txen. if bit sren is set (to interrupt an on-going trans- mission and receive a single word), then after the sin- gle word is received, bit sren will be cleared and the serial port will revert back to transmitting since bit txen is still set. the dt line will immediately switch from hi-impedance receive mode to transmit and start driving. to avoid this, bit txen should be cleared. in order to select 9-bit transmission, the tx9 (txsta<6>) bit should be set and the ninth bit should be written to bit tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg can result in an immediate transfer of the data to the tsr register (if the tsr is empty). if the tsr was empty and the txreg was written before writing the ?new? tx9d, the ?present? value of bit tx9d is loaded. follow these steps when setting up a synchronous master transmission: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. initialize the spbrg register for the appropriate baud rate (section 12.1). 3. enable the synchronous master serial port by setting bits sync, spen, and csrc. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set bit tx9. 6. enable the transmission by setting bit txen. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. start transmission by loading data to the txreg register.
pic16f627a/628a/648a ds40044a-page 84 preliminary ? 2002 microchip technology inc. table 12-9: registers associated with synchronous master transmission figure 12-12: synchronous transmission figure 12-13: synchronous transmission (through txen) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. shaded cells are not used for synchronous master transmission. bit 0 bit 1 bit 7 word 1 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1 q2q3q4 q1q2q3q4 bit 2 bit 0 bit 1 bit 7 rb1/rx/dt pin rb2/tx/ck pin write to txreg reg txif bit (interrupt flag) trmt txen bit '1' '1' word 2 trmt bit write word1 write word2 note: sync master mode; spbrg = ?0?. continuous transmission of two 8-bit words. rb1/rx/dt pin rb2/tx/ck pin write to txreg reg txif bit trmt bit bit0 bit1 bit2 bit6 bit7 txen bit
? 2002 microchip technology inc. preliminary ds40044a-page 85 pic16f627a/628a/648a 12.4.2 usart synchronous master reception once synchronous mode is selected, reception is enabled by setting either enable bit sren (rcsta<5>) or enable bit cren (rcsta<4>). data is sampled on the rb1/rx/dt pin on the falling edge of the clock. if enable bit sren is set, then only a single word is received. if enable bit cren is set, the recep- tion is continuous until cren is cleared. if both bits are set then cren takes precedence. after clocking the last bit, the received data in the receive shift register (rsr) is transferred to the rcreg register (if it is empty). when the transfer is complete, interrupt flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read only bit which is reset by the hardware. in this case it is reset when the rcreg register has been read and is empty. the rcreg is a double buffered register, (i.e., it is a two deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting into the rsr register. on the clocking of the last bit of the third byte, if the rcreg register is still full then overrun error bit oerr (rcsta<1>) is set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. bit oerr has to be cleared in software (by clearing bit cren). if bit oerr is set, transfers from the rsr to the rcreg are inhibited, so it is essential to clear bit oerr if it is set. the 9th receive bit is buffered the same way as the receive data. reading the rcreg register, will load bit rx9d with a new value, therefore it is essential for the user to read the rcsta register before reading rcreg in order not to lose the old rx9d information. follow these steps when setting up a synchronous master reception: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. initialize the spbrg register for the appropriate baud rate. (section 12.1) 3. enable the synchronous master serial port by setting bits sync, spen, and csrc. 4. ensure bits cren and sren are clear. 5. if interrupts are desired, then set enable bit rcie. 6. if 9-bit reception is desired, then set bit rx9. 7. if a single reception is required, set bit sren. for continuous reception set bit cren. 8. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 9. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 10. read the 8-bit received data by reading the rcreg register. 11. if any error occurred, clear the error by clearing bit cren. table 12-10: registers associated with synchronous master reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eepie cmie rcie txie ? ccp1ie tmr2ie tmr1ie -000 0000 -000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as '0'. shaded cells are not used for synchronous master reception.
pic16f627a/628a/648a ds40044a-page 86 preliminary ? 2002 microchip technology inc. figure 12-14: synchronous reception (master mode, sren) 12.5 usart synchronous slave mode synchronous slave mode differs from the master mode in the fact that the shift clock is supplied externally at the rb2/tx/ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in sleep mode. slave mode is entered by clearing bit csrc (txsta<7>). 12.5.1 usart synchronous slave transmit the operation of the synchronous master and slave modes are identical except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep and if the global interrupt is enabled, the program will branch to the inter- rupt vector (0004h). follow these steps when setting up a synchronous slave transmission: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. enable the synchronous slave serial port by set- ting bits sync and spen and clearing bit csrc. 3. clear bits cren and sren. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set bit tx9. 6. enable the transmission by setting enable bit txen. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. start transmission by loading data to the txreg register. cren bit rb1/rx/dt pin rb2/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg q3q4q1q2q3q4q1q2q3q4 q2 q1q2q3q4q1q2q3q4 q1q2q3q4q1q2q3 q4q1q2q3q4q1q2q3q4q1q2q3q4 '0' bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 '0' q1q2q3q4 note: timing diagram demonstrates sync master mode with bit sren = ?1? and bit brg = ?0?.
? 2002 microchip technology inc. preliminary ds40044a-page 87 pic16f627a/628a/648a 12.5.2 usart synchronous slave reception the operation of the synchronous master and mlave modes is identical except in the case of the sleep mode. also, bit sren is a don't care in slave mode. if receive is enabled, by setting bit cren, prior to the sleep instruction, then a word may be received during sleep. on completely receiving the word, the rsr register will transfer the data to the rcreg register and if enable bit rcie bit is set, the interrupt generated will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). follow these steps when setting up a synchronous slave reception: 1. trisb<1> bit needs to be set and trisb<2> bit cleared in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter pins. 2. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 3. if interrupts are desired, then set enable bit rcie. 4. if 9-bit reception is desired, then set bit rx9. 5. to enable reception, set enable bit cren. 6. flag bit rcif will be set when reception is com- plete and an interrupt will be generated, if enable bit rcie was set. 7. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing bit cren. table 12-11: registers associated with synchronous slave transmission table 12-12: registers associated with synchronous slave reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as '0'. shaded cells are not used for synchronous slave transmission. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as '0'. shaded cells are not used for synchronous slave reception.
pic16f627a/628a/648a ds40044a-page 88 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 89 pic16f627a/628a/648a 13.0 data eeprom memory the eeprom data memory is readable and writable during normal operation (full v dd range). this memory is not directly mapped in the register file space. instead it is indirectly addressed through the special function registers (sfrs). there are four sfrs used to read and write this memory. these registers are: eecon1  eecon2 (not a physically implemented register) eedata eeadr eedata holds the 8-bit data for read/write, and eeadr holds the address of the eeprom location being accessed. pic16f627a/628a devices have 128 bytes of data eeprom with an address range from 0h to 7fh. pic16f648a device has 256 bytes of data eeprom with an address range from 0h to ffh. the eeprom data memory allows byte read and write. a byte write automatically erases the location and writes the new data (erase before write). the eeprom data memory is rated for high erase/write cycles. the write time is controlled by an on-chip timer. the write- time will vary with voltage and temperature as well as from chip to chip. please refer to ac specifications for exact limits. when the device is code protected, the cpu can continue to read and write the data eeprom memory. a device programmer can no longer access this memory. additional information on the data eeprom is avail- able in the picmicro? mid-range reference manual, (ds33023). register 13-1: eedata register (address: 9ah) register 13-2: eeadr register (address: 9bh) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eedat7 eedat6 eedat5 eedat4 eedat3 eedat2 eedat1 eedat0 bit 7 bit 0 bit 7-0 eedatn : byte value to write to or read from data eeprom memory location. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eadr7 eadr6 eadr5 eadr4 eadr3 eadr2 eadr1 eadr0 bit 7 bit 0 bit 7 pic16f627a/628a - unimplemented address: must be set to ?0? pic16f648a - eeadr : set to ?1? specifies top 128 locations (128-256) of eeprom read/write operation bit 6-0 eeadr : specifies one of 128 locations of eeprom read/write operation legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f627a/628a/648a ds40044a-page 90 preliminary ? 2002 microchip technology inc. 13.1 eeadr the pic16f648a eeadr register addresses 256 bytes of data eeprom. all eight bits in the register (eeadr<7:0>) are required. the pic16f627a/628a eeadr register addresses only the first 128 bytes of data eeprom so only seven of the eight bits in the register (eeadr<6:0>) are required. the upper bit is address decoded. this means that this bit should always be '0' to ensure that the address is in the 128 byte memory space. 13.2 eecon1 and eecon2 registers eecon1 is the control register with four low order bits physically implemented. the upper-four bits are non- existent and read as '0's. control bits rd and wr initiate read and write, respectively. these bits cannot be cleared, only set, in software. they are cleared in hardware at completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental, premature termination of a write operation. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time out reset during normal opera- tion. in these situations, following reset, the user can check the wrerr bit and rewrite the location. the data and address will be unchanged in the eedata and eeadr registers. interrupt flag bit eeif in the pir1 register is set when write is complete. this bit must be cleared in software. eecon2 is not a physical register. reading eecon2 will read all '0's. the eecon2 register is used exclusively in the data eeprom write sequence. register 13-3: eecon1 register (address: 9ch) devices u-0 u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 ? ? ? ? wrerr wren wr rd bit 7 bit 0 bit 7-4 unimplemented: read as '0' bit 3 wrerr : eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset, any wdt reset during nor- mal operation or bor reset) 0 = the write operation completed bit 2 wren : eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the data eeprom bit 1 wr : write control bit 1 = initiates a write cycle. (the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software. 0 = write cycle to the data eeprom is complete bit 0 rd : read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software). 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 91 pic16f627a/628a/648a 13.3 reading the eeprom data memory to read a data memory location, the user must write the address to the eeadr register and then set control bit rd (eecon1<0>). the data is available, in the very next cycle, in the eedata register; therefore it can be read in the next instruction. eedata will hold this value until another read or until it is written to by the user (during a write operation). example 13-1: data eeprom read 13.4 writing to the eeprom data memory to write an eeprom data location, the user must first write the address to the eeadr register and the data to the eedata register. then the user must follow a specific sequence to initiate the write for each byte. example 13-2: data eeprom write the write will not initiate if the above sequence is not exactly followed (write 55h to eecon2, write aah to eecon2, then set wr bit) for each byte. we strongly recommend that interrupts be disabled during this code segment. a cycle count is executed during the required sequence. any number what is not equal to the required cycles to execute the required sequence will cause the data not to be written into the eeprom. additionally, the wren bit in eecon1 must be set to enable write. this mechanism prevents accidental writes to data eeprom due to errant (unexpected) code execution (i.e., lost programs). the user should keep the wren bit clear at all times, except when updating eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, clearing the wren bit will not affect this write cycle. the wr bit will be inhibited from being set unless the wren bit is set. at the completion of the write cycle, the wr bit is cleared in hardware and the ee write complete interrupt flag bit (eeif) is set. the user can either enable this interrupt or poll this bit. the eeif bit in the pir1 registers must be cleared by software. 13.5 write verify depending on the application, good programming practice may dictate that the value written to the data eeprom should be verified (example 13-3) to the desired value to be written. this should be used in applications where an eeprom bit will be stressed near the specification limit. example 13-3: write verify 13.6 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built in. on power-up, wren is cleared. also when enabled, the power-up timer (72 ms duration) prevents eeprom write. the write initiate sequence, and the wren bit together help prevent an accidental write during brown-out, power glitch, or software malfunction. bsf status, rp0 ;bank 1 movlw config_addr ; movwf eeadr ;address to read bsf eecon1, rd ;ee read movf eedata, w ;w = eedata bcf status, rp0 ;bank 0 required sequence bsf status, rp0 ;bank 1 bsf eecon1, wren ;enable write bcf intcon, gie ;disable ints. movlw 55h ; movwf eecon2 ;write 55h movlw aah ; movwf eecon2 ;write aah bsf eecon1,wr ;set wr bit ;begin write bsf intcon, gie ;enable ints. bsf status, rp0 ;bank 1 movf eedata, w bsf eecon1, rd ;read the ;value written ; ;is the value written (in w reg) and ;read (in eedata) the same? ; subwf eedata, w ; btfss status, z ;is difference 0? goto write_err ;no, write error : ;yes, good write : ;continue program
pic16f627a/628a/648a ds40044a-page 92 preliminary ? 2002 microchip technology inc. 13.7 using the data eeprom the data eeprom is a high endurance, byte address- able array that has been optimized for the storage of frequently changing information (e.g., program vari- ables or other data that are updated often). frequently changing values will typically be updated more often than specification d124. if this is not the case, an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, cali- bration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 13-4. example 13-4: data eeprom refresh routine 13.8 data eeprom operation during code protect when the device is code protected, the cpu is able to read and write data to the data eeprom. table 13-1: registers/bits associated with data eeprom note: if data eeprom is only used to store con- stants and/or data that changes rarely, an array refresh is likely not required. see specification d124. clrf eeadr ; start at address 0 bcf eecon1,cfgs ; set for memory bcf eecon1,eepgd ; set for data eeprom bcf intcon,gie ; disable interrupts bsf eecon1,wren ; enable writes loop ; loop to refresh array bsf eecon1,rd ; read current address movlw 55h ; movwf eecon2 ; write 55h movlw aah ; movwf eecon2 ; write aah bsf eecon1,wr ; set wr bit to begin write btfsc eecon1,wr ; wait for write to complete bra $-2 incfsz eeadr,f ; increment address bra loop ; not zero, do it again bcf eecon1,wren ; disable writes bsf intcon,gie ; enable interrupts address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on power-on reset value on all other resets 9ah eedata eeprom data register xxxx xxxx uuuu uuuu 9bh eeadr eeprom address register xxxx xxxx uuuu uuuu 9ch eecon1 ? ? ? ? wrerr wren wr rd ---- x000 ---- q000 9dh eecon2 (1) eeprom control register 2 ---- ---- ---- ---- legend: x = unknown, u = unchanged, - = unimplemented read as '0', q = value depends upon condition. shaded cells are not used by data eeprom. note 1: eecon2 is not a physical register
? 2002 microchip technology inc. preliminary ds40044a-page 93 pic16f627a/628a/648a 14.0 special features of the cpu special circuits to deal with the needs of real-time applications are what sets a microcontroller apart from other processors. the pic16f627a/628a/648a family has a host of such features intended to maximize sys- tem reliability, minimize cost through elimination of external components, provide power saving operating modes and offer code protection. these are: 1. osc selection 2. reset 3. power-on reset (por) 4. power-up timer (pwrt) 5. oscillator start-up timer (ost) 6. brown-out reset (bor) 7. interrupts 8. watchdog timer (wdt) 9. sleep 10. code protection 11. id locations 12. in-circuit serial programming? (icsp?) the pic16f627a/628a/648a has a watchdog timer which is controlled by configuration bits. it runs off its own rc oscillator for added reliability. there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which pro- vides a fixed delay of 72 ms (nominal) on power-up only, designed to keep the part in reset while the power supply stabilizes. there is also circuitry to reset the device if a brown-out occurs. with these three functions on-chip, most applications need no external reset circuitry. the sleep mode is designed to offer a very low current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up or through an interrupt. several oscillator options are also made available to allow the part to fit the application. the rc oscillator option saves system cost while the lp crystal option saves power. a set of configuration bits are used to select various options. 14.1 configuration bits the configuration bits can be programmed (read as '0') or left unprogrammed (read as '1') to select various device configurations. these bits are mapped in program memory location 2007h. the user will note that address 2007h is beyond the user program memory space. in fact, it belongs to the special configuration memory space (2000h ? 3fffh), which can be accessed only during program- ming. see programming specification (ds41196) for additional information.
pic16f627a/628a/648a ds40044a-page 94 preliminary ? 2002 microchip technology inc. register 14-1: configuration word cp cpd lvp boren mclre fosc2 pwrte wdte f0sc1 f0sc0 bit 13 bit 0 bit 13: cp: flash program memory code protection bit (2) ( pic16f648a ) 1 = code protection off 0 = 0000h to 0fffh code protected ( pic16f628a ) 1 = code protection off 0 = 0000h to 07ffh code protected ( pic16f627a ) 1 = code protection off 0 = 0000h to 03ffh code protected bit 12-9: unimplemented : read as 0 bit 8: cpd: data code protection bit (3) 1 = data memory code protection off 0 = data memory code protected bit 7: lvp : low voltage programming enable 1 = rb4/pgm pin has pgm function, low voltage programming enabled 0 = rb4/pgm is digital i/o, hv on mclr must be used for programming bit 6: boren : brown-out reset enable bit (1) 1 = bor reset enabled 0 = bor reset disabled bit 5: mclre : ra5/mclr pin function select 1 = ra5/mclr pin function is mclr 0 = ra5/mclr pin function is digital input, mclr internally tied to v dd bit 3: pwrten : power-up timer enable bit (1) 1 = pwrt disabled 0 = pwrt enabled bit 2: wdten : watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled bit 4, 1-0: fosc2:fosc0 : oscillator selection bits (4) 111 = rc oscillator: clkout function on ra6/osc2/clkout pin, resistor and capacitor on ra7/osc1/clkin 110 = rc oscillator: i/o function on ra6/osc2/clkout pin, resistor and capacitor on ra7/osc1/clkin 101 = intosc oscillator: clkout function on ra6/osc2/clkout pin, i/o function on ra7/osc1/clkin 100 = intosc oscillator: i/o function on ra6/osc2/clkout pin, i/o function on ra7/osc1/clkin 011 = ec: i/o function on ra6/osc2/clkout pin, clkin on ra7/osc1/clkin 010 = hs oscillator: high speed crystal/resonator on ra6/osc2/clkout and ra7/osc1/clkin 001 = xt oscillator: crystal/resonator on ra6/osc2/clkout and ra7/osc1/clkin 000 = lp oscillator: low power crystal on ra6/osc2/clkout and ra7/osc1/clkin note 1: enabling brown-out reset does not automatically enable the power-up timer (pwrt) the way it did in the pic16f627/628. 2: the code protection scheme has changed from the code protection scheme used in the pic16f627/628. the entire flash program memory needs to be bulk erased to set the cp bit, turning the code protection off. see programming specification ds41196 for de tails. 3: the entire data eeprom needs to be bulk erased to set the cpd bit, turning the code protection off. see programming specificati on ds41196 for details. 4: when mclr is asserted in intosc mode, the internal clock oscillator is disabled. legend r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown
? 2002 microchip technology inc. preliminary ds40044a-page 95 pic16f627a/628a/648a 14.2 oscillator configurations 14.2.1 oscillator types the pic16f627a/628a/648a can be operated in eight different oscillator options. the user can program three configuration bits (fosc2 through fosc0) to select one of these eight modes:  lp low power crystal  xt crystal/resonator  hs high speed crystal/resonator  rc external resistor/capacitor (2 modes)  intosc internal precision oscillator (2 modes)  ec external clock in 14.2.2 crystal oscillator / ceramic resonators in xt, lp or hs modes a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation (figure 14-1). the pic16f627a/628a/648a oscillator design requires the use of a parallel cut crys- tal. use of a series cut crystal may give a frequency out of the crystal manufacturers specifications. when in xt, lp or hs modes, the device can have an external clock source to drive the osc1 pin (figure 14-4). figure 14-1: crystal operation (or ceramic resonator) (hs, xt or lp osc configuration) table 14-1: capacitor selection for ceramic resonators table 14-2: capacitor selection for crystal oscillator 14.2.3 external crystal oscillator circuit either a prepackaged oscillator can be used or a simple oscillator circuit with ttl gates can be built. prepackaged oscillators provide a wide operating range and better stability. a well-designed crystal oscillator will provide good performance with ttl gates. two types of crystal oscillator circuits can be used; one with series resonance, or one with parallel resonance. figure 14-2 shows implementation of a parallel reso- nant oscillator circuit. the circuit is designed to use the fundamental frequency of the crystal. the 74as04 inverter performs the 180 phase shift that a parallel oscillator requires. the 4.7 k ? resistor provides the negative feedback for stability. the 10 k ? potentiometers bias the 74as04 in the linear region. this could be used for external oscillator designs. note 1: a series resistor may be required for at strip cut crystals. 2: see table 14-1 and table 14-2 for recommended values of c1 and c2. c1 c2 xtal osc2 rs (1) osc1 rf sleep pic16f627a/628a/648a f osc mode freq osc1(c1) osc2(c2) xt 455 khz 2.0 mhz 4.0 mhz 22 - 100 pf 15 - 68 pf 15 - 68 pf 22 - 100 pf 15 - 68 pf 15 - 68 pf hs 8.0 mhz 16.0 mhz 10 - 68 pf 10 - 22 pf 10 - 68 pf 10 - 22 pf note: higher capacitance increases the stability of the oscil- lator but also increases the start-up time. these values are for design guidance only. since each resonator has its own characteristics, the user should consult the res- onator manufacturer for appropriate values of external components. mode freq osc1(c1) osc2(c2) lp 32 khz 200 khz 15 - 30 pf 0 - 15 pf 15 - 30 pf 0 - 15 pf xt 100 khz 2 mhz 4 mhz 68 - 150 pf 15 - 30 pf 15 - 30 pf 150 - 200 pf 15 - 30 pf 15 - 30 pf hs 8 mhz 10 mhz 20 mhz 15 - 30 pf 15 - 30 pf 15 - 30 pf 15 - 30 pf 15 - 30 pf 15 - 30 pf note: higher capacitance increases the stability of the oscil- lator but also increases the start-up time. these values are for design guidance only. a series resistor (rs) may be required in hs mode as well as xt mode to avoid overdriving crystals with low drive level specifica- tion. since each crystal has its own characteristics, the user should consult the crystal manufacturer for appro- priate values of external components.
pic16f627a/628a/648a ds40044a-page 96 preliminary ? 2002 microchip technology inc. figure 14-2: external parallel resonant crystal oscillator circuit figure 14-3 shows a series resonant oscillator circuit. this circuit is also designed to use the fundamental frequency of the crystal. the inverter performs a 180 phase shift in a series resonant oscillator circuit. the 330 k ? resistors provide the negative feedback to bias the inverters in their linear region. figure 14-3: external series resonant crystal oscillator circuit 14.2.4 precision internal 4 mh z oscillator the internal precision oscillator provides a fixed 4 mhz (nominal) system clock at v dd = 5 v and 25 c. see section 17.0, electrical specifications, for information on variation over voltage and temperature. 14.2.5 external clock in for applications where a clock is already available elsewhere, users may directly drive the pic16f627a/ 628a/648a provided that this external clock source meets the ac/dc timing requirements listed in section 17.6. figure 14-4 below shows how an exter- nal clock circuit should be configured. figure 14-4: external clock input operation (ec, hs, xt or lp osc configuration) 14.2.6 rc oscillator for applications where precise timing is not a require- ment, the rc oscillator option is available. the opera- tion and functionality of the rc oscillator is dependent upon a number of variables. the rc oscillator fre- quency is a function of:  supply voltage  resistor (r ext ) and capacitor (c ext ) values  operating temperature. the oscillator frequency will vary from unit to unit due to normal process parameter variation. the difference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low c ext values. the user also needs to account for the tolerance of the external r and c components. figure 14-5 shows how the r/c combination is con- nected. figure 14-5: rc oscillator mode the rc oscillator mode has two options that control the unused osc2 pin. the first allows it to be used as a general purpose i/o port. the other configures the pin as an output providing the fosc signal (internal clock divided by 4) for test or external synchronization purposes. 14.2.7 clkout the pic16f627a/628a/648a can be configured to pro- vide a clock out signal by programming the configura- tion word. the oscillator frequency, divided by 4 can be used for test purposes or to synchronize other logic. +5v 10k 4.7k 10k 74as04 xtal 10k 74as04 pic16f627a/628a/648a clkin to other devices c1 c2 330 k ? 74as04 74as04 pic16f627a/ clkin to other devices xtal 330 k ? 74as04 0.1 pf 628a/648a clock from ext. system pic16f627a/628a/648a ra6 ra7/osc1/clkin ra6/osc2/clkout c ext v dd r ext v ss pic16f627a/628a/648a f osc /4 internal clock clkin ra7/osc1/ ra6/osc2/clkout
? 2002 microchip technology inc. preliminary ds40044a-page 97 pic16f627a/628a/648a 14.2.8 special feature: dual speed oscillator modes a software programmable dual speed oscillator mode is provided when the pic16f627a/628a/648a is con- figured in the intosc oscillator mode. this feature allows users to dynamically toggle the oscillator speed between 4 mhz and 37 khz nominal in the intosc mode. applications that require low current power sav- ings, but cannot tolerate putting the part into sleep, may use this mode. there is a time delay associated with the transition between fast and slow oscillator speeds. this oscilla- tor speed transition delay consists of two existing clock pulses and eight new speed clock pulses. during this clock speed transition delay the system clock is halted causing the processor to be frozen in time. dur- ing this delay the program counter and the clock out stop. the oscf bit in the pcon register is used to control dual speed mode. see section 4.2.2.6, register 4-6. 14.3 reset the pic16f627a/628a/648a differentiates between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during sleep d) wdt reset (normal operation) e) wdt wake-up (sleep) f) brown-out reset (bor) some registers are not affected in any reset condi- tion; their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on power-on reset, brown-out reset, mclr reset, wdt reset and mclr reset during sleep. they are not affected by a wdt wake-up, since this is viewed as the resumption of normal oper- ation. to and pd bits are set or cleared differently in different reset situations as indicated in table 14-4. these bits are used in software to determine the nature of the reset. see table 14-7 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 14-6. the mclr reset path has a noise filter to detect and ignore small pulses. see table 17-7 for pulse width specification. figure 14-6: simplified block diagram of on-chip reset circuit s r q external reset mclr / v dd osc1/ wdt module v dd rise detect ost/pwrt wdt time out power-on reset ost pwrt chip_reset 10-bit ripple-counter reset enable ost enable pwrt sleep see table 14-3 for time out situations. note 1: this is a separate oscillator from the intosc/rc oscillator. brown-out detect reset boren clkin pin v pp pin 10-bit ripple-counter q schmitt trigger input on-chip (1) osc
pic16f627a/628a/648a ds40044a-page 98 preliminary ? 2002 microchip technology inc. 14.4 power-on reset (por), power-up timer (pwrt), oscillator start-up timer (ost) and brown-out reset (bor) 14.4.1 power-on reset (por) the on-chip por circuit holds the chip in reset until v dd has reached a high enough level for proper oper- ation. to take advantage of the por, just tie the mclr pin through a resistor to v dd . this will eliminate exter- nal rc components usually needed to create power-on reset. a maximum rise time for v dd is required. see electrical specifications for details. the por circuit does not produce an internal reset when v dd declines. when the device starts normal operation (exits the reset condition), device operating parameters (volt- age, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating con- ditions are met. for additional information, refer to application note an607, ?power-up trouble shooting?. 14.4.2 power-up timer (pwrt) the pwrt provides a fixed 72 ms (nominal) time out on power-up (por) or if enabled from a brown-out reset. the pwrt operates on an internal rc oscilla- tor. the chip is kept in reset as long as pwrt is active. the pwrt delay allows the v dd to rise to an acceptable level. a configuration bit, pwrte can disable (if set) or enable (if cleared or programmed) the pwrt. it is recommended that the pwrt be enabled when brown-out reset is enabled. the power-up time delay will vary from chip to chip and due to v dd , temperature and process variation. see dc parameters table 17-7 for details. 14.4.3 oscillator start-up timer (ost) the ost provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over. program execution will not start until the ost time out is com- plete. this ensures that the crystal oscillator or resona- tor has started and stabilized. the ost time out is invoked only for xt, lp and hs modes and only on power-on reset or wake-up from sleep. see table 17-7. 14.4.4 brown-out reset (bor) the pic16f627a/628a/648a have on-chip bor cir- cuitry. a configuration bit, boren, can disable (if clear/ programmed) or enable (if set) the bor reset circuitry. if v dd falls below v bor for longer than t bor , the brown-out situation will reset the chip. a reset is not guaranteed to occur if v dd falls below v bor for shorter than t bor . v bor and t bor are defined in table 17-2 and table 17-7, respectively. on any reset (power-on, brown-out, watchdog, etc.), the chip will remain in reset until v dd rises above bv dd (see figure 14-7). the power-up timer will now be invoked, if enabled, and will keep the chip in reset an additional 72 ms. if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be re-initialized. once v dd rises above v bor , the power-up timer will execute a 72 ms reset. figure 14-7 shows typical brown-out situations. figure 14-7: brown-out situations with pwrt enabled 72 ms v bor v dd internal reset v bor v dd internal reset 72 ms <72 ms 72 ms v bor v dd internal reset t bor note: 72 ms delay only if pwrte bit is programmed to ?0?.
? 2002 microchip technology inc. preliminary ds40044a-page 99 pic16f627a/628a/648a 14.4.5 time out sequence on power-up the time out sequence is as follows: first pwrt time out is invoked after por has expired. then ost is activated. the total time out will vary based on oscillator configuration and pwrte bit status. for example, in rc mode with pwrte bit set (pwrt dis- abled), there will be no time out at all. figure 14-8, figure 14-9 and figure 14-10 depict time out sequences. since the time outs occur from the por pulse, if mclr is kept low long enough, the time outs will expire. then bringing mclr high will begin execution immediately (see figure 14-9). this is useful for testing purposes or to synchronize more than one pic16f627a/628a/ 648a device operating in parallel. table 14-6 shows the reset conditions for some spe- cial registers, while table 14-7 shows the reset con- ditions for all the registers. 14.4.6 power control (pcon) status register the power control/status register, pcon (address 8eh) has two bits. bit0 is bor (brown-out reset). bor is unknown on power-on-reset. it must then be set by the user and checked on subsequent resets to see if bor = 0 indicating that a brown-out has occurred. the bor status bit is a don?t care and is not necessarily predictable if the brown-out circuit is disabled (by setting boren bit = 0 in the configuration word). bit1 is por (power-on reset). it is a ?0? on power-on reset and unaffected otherwise. the user must write a ?1? to this bit following a power-on reset. on a subse- quent reset if por is ?0?, it will indicate that a power- on reset must have occurred (v dd may have gone too low). table 14-3: time out in various situations table 14-4: status/pcon bits and their significance oscillator configuration power-up brown-out reset wake-up from sleep pwrten = 0 pwrten = 1 pwrten = 0 pwrten = 1 xt, hs, lp 72 ms + 1024t osc 1024t osc 72 ms + 1024t osc 1024t osc 1024t osc rc, ec 72 ms ? 72 ms ?? intosc 72 ms ? 72 ms ? 6 s por bor to pd condition 0x11 power-on reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 10xx brown-out reset 110u wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep legend: u = unchanged, x = unknown.
pic16f627a/628a/648a ds40044a-page 100 preliminary ? 2002 microchip technology inc. table 14-5: summary of registers associated with brown-out reset table 14-6: initialization condition for special registers addressnamebit 7bit 6bit 5bit 4bit 3bit 2 bit 1bit 0 value on por reset value on all other resets (1) 03h, 83h, 103h, 183h status irp rp1 rpo to pd z dc c 0001 1xxx 000q quuu 8eh pcon ? ? ? ? oscf ?por bor ---- 1-0x ---- u-uq legend: x = unknown, u = unchanged, - = unimplemented read as '0', q = value depends upon condition. shaded cells are not used by brown-out reset. note 1: other (non power-up) resets include mclr reset, brown-out reset and watchdog timer reset during normal operation. condition program counter status register pcon register power-on reset 000h 0001 1xxx ---- 1-0x mclr reset during normal operation 000h 000u uuuu ---- 1-uu mclr reset during sleep 000h 0001 0uuu ---- 1-uu wdt reset 000h 0000 uuuu ---- 1-uu wdt wake-up pc + 1 uuu0 0uuu ---- u-uu brown-out reset 000h 000x xuuu ---- 1-u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- u-uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ?0?. note 1: when the wake-up is due to an interrupt and global enable bit, gie is set, the pc is loaded with the interrupt vector (0004h) after execution of pc+1.
? 2002 microchip technology inc. preliminary ds40044a-page 101 pic16f627a/628a/648a table 14-7: initialization condition for registers register address power-on reset  mclr reset during normal operation  mclr reset during sleep  wdt reset  brown-out reset (1)  wake-up from sleep (7) through interrupt  wake-up from sleep (7) through wdt time out w? xxxx xxxx uuuu uuuu uuuu uuuu indf 00h ? ? ? tmr0 01h, 101h xxxx xxxx uuuu uuuu uuuu uuuu pcl 02h, 82h, 102h, 182h 0000 0000 0000 0000 pc + 1 (3) status 03h, 83h, 103h, 183h 0001 1xxx 000q quuu (4) uuuq 0uuu (4) fsr 04h, 84h, 104h, 184h xxxx xxxx uuuu uuuu uuuu uuuu porta 05h xxxx 0000 xxxx 0000 uuuu uuuu portb 06h, 106h xxxx xxxx uuuu uuuu uuuu uuuu pclath 0ah, 8ah, 10ah, 18ah ---0 0000 ---0 0000 ---u uuuu intcon 0bh, 8bh, 10bh,18bh 0000 000x 0000 000u uuuu uqqq (2) pir1 0ch 0000 -000 0000 -000 qqqq -qqq (2) tmr1l 0eh xxxx xxxx uuuu uuuu uuuu uuuu tmr1h 0fh xxxx xxxx uuuu uuuu uuuu uuuu t1con 10h --00 0000 --uu uuuu (6) --uu uuuu tmr2 11h 0000 0000 0000 0000 uuuu uuuu t2con 12h -000 0000 -000 0000 -uuu uuuu ccpr1l 15h xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h 16h xxxx xxxx uuuu uuuu uuuu uuuu ccp1con 17h --00 0000 --00 0000 --uu uuuu rcsta 18h 0000 000x 0000 000x uuuu uuuu txreg 19h 0000 0000 0000 0000 uuuu uuuu rcreg 1ah 0000 0000 0000 0000 uuuu uuuu cmcon 1fh 0000 0000 0000 0000 uu-- uuuu option 81h,181h 1111 1111 1111 1111 uuuu uuuu trisa 85h 1111 1111 1111 1111 uuuu uuuu trisb 86h, 186h 1111 1111 1111 1111 uuuu uuuu pie1 8ch 0000 -000 0000 -000 uuuu -uuu pcon 8eh ---- 1-0x ---- 1-uq (1,5) ---- u-uu pr2 92h 1111 1111 1111 1111 uuuu uuuu txsta 98h 0000 -010 0000 -010 uuuu -uuu spbrg 99h 0000 0000 0000 0000 uuuu uuuu eedata 9ah xxxx xxxx uuuu uuuu uuuu uuuu eeadr 9bh xxxx xxxx uuuu uuuu uuuu uuuu eecon1 9ch ---- x000 ---- q000 ---- uuuu eecon2 9dh ? ? ? vrcon 9fh 000- 0000 000- 0000 uuu- uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ?0?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 14-6 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0. all other resets will cause bit 0 = u. 6: reset to ? -- 00 0000? on a brown-out reset (bor). 7: peripherals generating interrupts for wake-up from sleep will change the resulting bits in the associated registers.
pic16f627a/628a/648a ds40044a-page 102 preliminary ? 2002 microchip technology inc. figure 14-8: time out sequence on power-up (mclr not tied to v dd ): case figure 14-9: time out sequence on power-up (mclr not tied to v dd ): case 2 figure 14-10: time out sequence on power-up (mclr tied to v dd ) tpwrt to s t v dd mclr internal por pwrt time out ost time out internal reset v dd mclr internal por pwrt time out ost time out internal reset tpwrt to s t tpwrt to s t v dd mclr internal por pwrt time out ost time out internal reset
? 2002 microchip technology inc. preliminary ds40044a-page 103 pic16f627a/628a/648a figure 14-11: external power-on reset circuit (for slow v dd power-up) figure 14-12: external brown-out protection circuit 1 figure 14-13: external brown-out protection circuit 2 note 1: external power-on reset circuit is required only if v dd power-up slope is too slow. the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure that voltage drop across r does not violate the device?s electrical specification. 3: r1 = 100 ? to 1 k ? will limit any current flowing into mclr from external capacitor c in the event of mclr /v pp pin breakdown due to electrostatic discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic16f627a/628a/648a v dd note 1: this circuit will activate reset when v dd goes below (vz + 0.7v) where vz = zener voltage. 2: internal brown-out reset circuitry should be disabled when using this circuit. v dd 33k 10k 40k v dd mclr pic16f627a/628a/648a vdd x r1 r1 + r2 = 0.7 v v dd r2 40k v dd mclr pic16f627a/628a/648a r1 q1 note 1: this brown-out circuit is less expensive, albeit less accurate. transistor q1 turns off when v dd is below a certain level such that: 2: internal brown-out reset should be dis- abled when using this circuit. 3: resistors should be adjusted for the charac- teristics of the transistor. v dd x r1 r1 + r2 = 0.7 v
pic16f627a/628a/648a ds40044a-page 104 preliminary ? 2002 microchip technology inc. 14.5 interrupts the pic16f627a/628a/648a has 10 sources of inter- rupt:  external interrupt rb0/int  tmr0 overflow interrupt  portb change interrupts (pins rb7:rb4)  comparator interrupt  usart interrupt tx  usart interrupt rx  ccp interrupt  tmr1 overflow interrupt  tmr2 match interrupt  data eeprom interrupt the interrupt control register (intcon) records individual interrupt requests in flag bits. it also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>) enables (if set) all un-masked interrupts or disables (if cleared) all interrupts. individual interrupts can be disabled through their corresponding enable bits in intcon register. gie is cleared on reset. the ?return from interrupt? instruction, retfie , exits interrupt routine as well as sets the gie bit, which re- enable rb0/int interrupts. the int pin interrupt, the rb port change interrupt and the tmr0 overflow interrupt flags are contained in the intcon register. the peripheral interrupt flag is contained in the special register pir1. the corresponding interrupt enable bit is contained in special registers pie1. when an interrupt is responded to, the gie is cleared to disable any further interrupt, the return address is pushed into the stack and the pc is loaded with 0004h. once in the interrupt service routine the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in soft- ware before re-enabling interrupts to avoid rb0/int recursive interrupts. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends when the interrupt event occurs (figure 14- 15). the latency is the same for one or two cycle instructions. once in the interrupt service routine the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid multiple interrupt requests. individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the gie bit. figure 14-14: interrupt logic note 1: individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the gie bit. 2: when an instruction that clears the gie bit is executed, any interrupts that were pending for execution in the next cycle are ignored. the cpu will execute a nop in the cycle immediately following the instruction which clears the gie bit. the interrupts which were ignored are still pending to be serviced when the gie bit is set again. tmr2if tmr2ie ccp1if ccp1ie cmif cmie txif txie rcif rcie t0if t0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) interrupt to cpu eeie eeif tmr1if tmr1ie
? 2002 microchip technology inc. preliminary ds40044a-page 105 pic16f627a/628a/648a 14.5.1 rb0/int interrupt external interrupt on rb0/int pin is edge triggered: either rising if intedg bit (option<6>) is set, or fall- ing, if intedg bit is clear. when a valid edge appears on the rb0/int pin, the intf bit (intcon<1>) is set. this interrupt can be disabled by clearing the inte control bit (intcon<4>). the intf bit must be cleared in software in the interrupt service routine before re- enabling this interrupt. the rb0/int interrupt can wake-up the processor from sleep, if the inte bit was set prior to going into sleep. the status of the gie bit decides whether or not the processor branches to the interrupt vector following wake-up. see section 14.8 for details on sleep, and figure 14-17 for timing of wake-up from sleep through rb0/int interrupt. 14.5.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set the t0if (intcon<2>) bit. the interrupt can be enabled/disabled by setting/clearing t0ie (intcon<5>) bit. for operation of the timer0 module, see section 6.0. 14.5.3 portb interrupt an input change on portb <7:4> sets the rbif (intcon<0>) bit. the interrupt can be enabled/dis- abled by setting/clearing the rbie (intcon<4>) bit. for operation of portb (section 5.2). 14.5.4 comparator interrupt see section 10.6 for complete description of compara- tor interrupts. figure 14-15: int pin interrupt timing note: if a change on the i/o pin should occur when the read operation is being executed (starts during the q2 cycle and ends before the start of the q3 cycle), then the rbif interrupt flag may not get set. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 osc1 clkout int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed interrupt latency pc pc+1 pc+1 0004h 0005h inst (0004h) inst (0005h) dummy cycle inst (pc) inst (pc+1) inst (pc-1) inst (0004h) dummy cycle inst (pc) ? note 1: intf flag is sampled here (every q1). 2: asynchronous interrupt latency = 3-4 tcy. synchronous latency = 3 tcy, where tcy = instruction cycle time. latency is the same whether inst (pc) is a single cycle or a 2-cycle instruction. 3: clkout is available in rc and intosc oscillator mode. 4: for minimum width of int pulse, refer to ac specs. 5: intf is enabled to be set anytime during the q4-q1 cycles. (1) (1) (4) (5) (2) (3)
pic16f627a/628a/648a ds40044a-page 106 preliminary ? 2002 microchip technology inc. table 14-8: summary of interrupt registers 14.6 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key reg- isters during an interrupt (e.g., w register and status register). this must be implemented in software. example 14-2 stores and restores the status and w registers. the user register, w_temp, must be defined in a common memory location (i.e., w_temp is defined at 0x70 in bank 0 and is therefore, accessible at 0xf0, 0x170 and 0x1f0). the example 14-2:  stores the w register  stores the status register  executes the isr code  restores the status (and bank select bit regis- ter)  restores the w register example 14-2: saving the status and w registers in ram 14.7 watchdog timer (wdt) the watchdog timer is a free running on-chip rc oscil- lator which does not require any external components. this rc oscillator is separate from the rc oscillator of the clkin pin. that means that the wdt will run, even if the clock on the osc1 and osc2 pins of the device has been stopped, for example, by execution of a sleep instruction. during normal operation, a wdt time out generates a device reset. if the device is in sleep mode, a wdt time out causes the device to wake-up and continue with normal operation. the wdt can be permanently disabled by programming the con- figuration bit wdte as clear (section 14.1). 14.7.1 wdt period the wdt has a nominal time out period of 18 ms (with no prescaler). the time out periods vary with tempera- ture, v dd and process variations from part to part (see dc specifications, table 17-7). if longer time out peri- ods are desired, a postscaler with a division ratio of up to 1:128 can be assigned to the wdt under software control by writing to the option register. thus, time out periods up to 2.3 seconds can be realized. the clrwdt and sleep instructions clear the wdt and the postscaler, if assigned to the wdt, and prevent it from timing out and generating a device reset. the to bit in the status register will be cleared upon a watchdog timer time out. 14.7.2 wdt programming considerations it should also be taken in account that under worst case conditions (v dd = min., temperature = max., max. wdt prescaler) it may take several seconds before a wdt time out occurs. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset value on all other resets (1) 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 note 1: other (non power-up) resets include mclr reset, brown-out reset and watchdog timer reset during normal oper- ation. movwf w_temp ;copy w to temp register, ;could be in any bank swapf status,w ;swap status to be saved ;into w bcf status,rp0 ;change to bank 0 ;regardless of current ;bank movwf status_temp ;save status to bank 0 ;register : :(isr) : swapf status_temp,w;swap status_temp register ;into w, sets bank to original ;state movwf status ;move w into status register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w
? 2002 microchip technology inc. preliminary ds40044a-page 107 pic16f627a/628a/648a figure 14-16: watchdog timer block diagram table 14-9: summary of watchdog timer registers 14.8 power-down mode (sleep) the power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit in the status register is cleared, the to bit is set, and the oscillator driver is turned off. the i/o ports maintain the status they had, before sleep was executed (driving high, low, or hi- impedance). for lowest current consumption in this mode, all i/o pins should be either at v dd , or v ss , with no external circuitry drawing current from the i/o pin and the com- parators, and v ref should be disabled. i/o pins that are hi-impedance inputs should be pulled high or low externally to avoid switching currents caused by float- ing inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on chip pull-ups on portb should be considered. the mclr pin must be at a logic high level (v ihmc ). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset value on all other resets 2007h config. bits lvp boren mclre fosc2 pwrte wdte fosc1 fosc0 uuuu uuuu uuuu uuuu 81h, 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented read as '0', q = value depends upon condition. note: shaded cells are not used by the watchdog timer. (figure 6-1) note: t0se, t0cs, psa, ps0-ps2 are bits in the option register. from tmr0 clock source watchdog timer wdt enable bit 0 1 8 8 to 1 mux ps<2:0> to tmr0 (figure 6-1) 01 psa wdt time out psa m u x mux 3 wdt postscaler/ tmr0 prescaler note: it should be noted that a reset generated by a wdt time out does not drive mclr pin low.
pic16f627a/628a/648a ds40044a-page 108 preliminary ? 2002 microchip technology inc. 14.8.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin 2. watchdog timer wake-up (if wdt was enabled) 3. interrupt from rb0/int pin, rb port change, or any peripheral interrupt. the first event will cause a device reset. the two lat- ter events are considered a continuation of program execution. the to and pd bits in the status register can be used to determine the cause of device reset. pd bit, which is set on power-up is cleared when sleep is invoked. to bit is cleared if wdt wake-up occurred. when the sleep instruction is being executed, the next instruction (pc + 1) is pre-fetched. for the device to wake-up through an interrupt event, the correspond- ing interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the inter- rupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have an nop after the sleep instruction. the wdt is cleared when the device wakes up from sleep, regardless of the source of wake-up. figure 14-17: wake-up from sleep through interrupt 14.9 code protection with the code protect bit is cleared (code protect enabled) the contents of the program memory locations are read out as ?00?. see programing specification, ds41196, for details. 14.10 user id locations four memory locations (2000h-2003h) are designated as user id locations where the user can store check- sum or other code-identification numbers. these loca- tions are not accessible during normal execution but are readable and writable during program/verify. only the least significant 4 bits of the user id locations are used. note: if the global interrupts are disabled (gie is cleared), but any interrupt source has both its interrupt enable bit and the correspond- ing interrupt flag bits set, the device will not enter sleep. the sleep instruction is executed as a nop instruction. q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clkout (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc+1 pc+2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency ( note 2 ) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle to s t (2) pc+2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024t osc (drawing not to scale). approximately 1 s delay will be there for rc osc mode. 3: gie = '1' assumed. in this case after wake-up, the processor jumps to the interrupt routine. if gie = '0', execution will conti nue in-line. 4: clkout is not available in these osc modes, but shown here for timing reference. note: only a bulk erase function can set the cp and cpd bits by turning off the code pro- tection. the entire data eeprom and flash program memory will be erased to turn the code protection off.
? 2002 microchip technology inc. preliminary ds40044a-page 109 pic16f627a/628a/648a 14.11 in-circuit serial programming the pic16f627a/628a/648a microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data, and three other lines for power, ground, and the pro- gramming voltage. this allows customers to manufac- ture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware, or a custom firmware to be programmed. the device is placed into a program/verify mode by holding the rb6 and rb7 pins low while raising the mclr (v pp ) pin from v il to v ihh (see programming specification). rb6 becomes the programming clock and rb7 becomes the programming data. both rb6 and rb7 are schmitt trigger inputs in this mode. after reset, to place the device into programming/ verify mode, the program counter (pc) is at location 00h. a 6-bit command is then supplied to the device. depending on the command, 14 bits of program data are then supplied to or from the device, depending if the command was a load or a read. for complete details of serial programming, please refer to the pro- gramming specifications (ds41196). a typical in-circuit serial programming connection is shown in figure 14-18. figure 14-18: typical in-circuit serial programming connection 14.12 low voltage programming the lvp bit of the configuration word, enables the low voltage programming. this mode allows the microcon- troller to be programmed via icsp using only a 5v source. this mode removes the requirement of v ihh to be placed on the mclr pin. the lvp bit is normally erased to '1' which enables the low voltage program- ming. in this mode, the rb4/pgm pin is dedicated to the programming function and ceases to be a general purpose i/o pin. the device will enter programming mode when a '1' is placed on the rb4/pgm pin. the hv programming mode is still available by placing v ihh on the mclr pin. if low-voltage programming mode is not used, the lvp bit should be programmed to a '0' so that rb4/pgm becomes a digital i/o pin. to program the device, v ihh must be placed onto mclr during programming. the lvp bit may only be programmed when programming is entered with v ihh on mclr . the lvp bit cannot be programmed when programming is entered with rb4/ pgm. it should be noted, that once the lvp bit is programmed to 0, only high voltage programming mode can be used to program the device. external connector signals to normal connections to normal connections pic16f627a/628a/648a v dd v ss ra5/mclr /v pp rb6/pgc rb7/pgd +5v 0v v pp clk data i/o v dd note 1: while in this mode the rb4 pin can no longer be used as a general purpose i/o pin. 2: v dd must be 5.0v + 10% during erase operations.
pic16f627a/628a/648a ds40044a-page 110 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 111 pic16f627a/628a/648a 15.0 instruction set summary each pic16f627a/628a/648a instruction is a 14-bit word divided into an opcode which specifies the instruction type and one or more operands which fur- ther specify the operation of the instruction. the pic16f627a/628a/648a instruction set summary in table 15-2 lists byte-oriented , bit-oriented , and lit- eral and control operations. table 15-1 shows the opcode field descriptions. for byte-oriented instructions, 'f' represents a file register designator and 'd' represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if 'd' is zero, the result is placed in the w register. if 'd' is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, 'b' represents a bit field designator which selects the number of the bit affected by the operation, while 'f' represents the number of the file in which the bit is located. for literal and control operations, 'k' represents an eight or eleven bit constant or literal value. table 15-1: opcode field descriptions the instruction set is highly orthogonal and is grouped into three basic categories:  byte-oriented operations  bit-oriented operations  literal and control operations all instructions are executed within one single instruction cycle, unless a conditional test is true or the program counter is changed as a result of an instruction. in this case, the execution takes two instruction cycles with the second cycle executed as a nop . one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. table 15-2 lists the instructions recognized by the mpasm? assembler. figure 15-1 shows the three general formats that the instructions can have. all examples use the following format to represent a hexadecimal number: 0xhh where h signifies a hexadecimal digit. figure 15-1: general format for instructions field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don't care location (= 0 or 1) the assembler will generate code with x = 0. it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0: store result in w, d = 1: store result in file register f. default is d = 1 label label name tos top of stack pc program counter pclath program counter high latch gie global interrupt enable bit wdt watchdog timer/counter to time out bit pd power-down bit dest destination either the w register or the specified regis- ter file location [ ] options ( ) contents assigned to < > register bit field in the set of italics user defined term (font is courier) note 1: any unused opcode is reserved. use of any reserved opcode may cause unex- pected operation. 2: to maintain upward compatibility with future picmicro products, do not use the option and tris instructions. byte-oriented file register operations d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations opcode k (literal) k = 8-bit immediate value opcode k (literal) k = 11-bit immediate value general call and goto instructions only 13 8 7 6 0 13 10 9 7 0 6 13 8 7 0 13 11 10 0
pic16f627a/628a/648a ds40044a-page 112 preliminary ? 2002 microchip technology inc. table 15-2: pic16f627a/628a/648a instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f ? f, d f, d f, d f, d f, d f, d f, d f ? f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1 (2) 1 1 (2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0000 dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff 0011 ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1,2 1,2 2 1,2 1,2 1,2,3 1,2 1,2,3 1,2 1,2 1,2 1,2 1,2 1,2 1,2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1,2 1,2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k ? k k k ? k ? ? k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to ,pd z to ,pd c,dc,z z note 1: when an i/o register is modified as a function of itself ( e.g., movf portb, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is '1' for a pin configured as input and is driven low by an external device, t he data will be written back with a '0'. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1), the prescaler will be cleared if assigned to the timer0 module. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is exe cuted as a nop .
? 2002 microchip technology inc. preliminary ds40044a-page 113 pic16f627a/628a/648a 15.1 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z encoding: 11 111x kkkk kkkk description: the contents of the w register are added to the eight bit literal 'k' and the result is placed in the w register . words: 1 cycles: 1 example addlw 0x15 before instruction w= 0x10 after instruction w= 0x25 addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [0,1] operation: (w) + (f) (dest) status affected: c, dc, z encoding: 00 0111 dfff ffff description: add the contents of the w register with register 'f'. if 'd' is 0 the result is stored in the w register. if 'd' is 1 the result is stored back in register 'f' . words: 1 cycles: 1 example addwf reg1, 0 before instruction w = 0x17 reg1 = 0xc2 after instruction w=0xd9 reg1 = 0xc2 z=0 c=0 dc = 0 andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z encoding: 11 1001 kkkk kkkk description: the contents of w register are and?ed with the eight bit literal 'k'. the result is placed in the w regis- ter . words: 1 cycles: 1 example andlw 0x5f before instruction w=0xa3 after instruction w = 0x03 andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [0,1] operation: (w) .and. (f) (dest) status affected: z encoding: 00 0101 dfff ffff description: and the w register with register 'f'. if 'd' is 0 the result is stored in the w register. if 'd' is 1 the result is stored back in register 'f' . words: 1 cycles: 1 example andwf reg1, 1 before instruction w = 0x17 reg1 = 0xc2 after instruction w = 0x17 reg1 = 0x02
pic16f627a/628a/648a ds40044a-page 114 preliminary ? 2002 microchip technology inc. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none encoding: 01 00bb bfff ffff description: bit 'b' in register 'f' is cleared . words: 1 cycles: 1 example bcf reg1, 7 before instruction reg1 = 0xc7 after instruction reg1 = 0x47 bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none encoding: 01 01bb bfff ffff description: bit 'b' in register 'f' is set. words: 1 cycles: 1 example bsf reg1, 7 before instruction reg1 = 0x0a after instruction reg1 = 0x8a btfsc bit test f, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none encoding: 01 10bb bfff ffff description: if bit 'b' in register 'f' is '0' then the next instruction is skipped. if bit 'b' is '0' then the next instruction fetched during the current instruction execution is discarded, and a nop is executed instead, making this a two- cycle instruction . words: 1 cycles: 1(2) example here false true btfsc goto    reg1 process_code before instruction pc = address here after instruction if reg<1> = 0, pc = address true if reg<1>=1, pc = address false
? 2002 microchip technology inc. preliminary ds40044a-page 115 pic16f627a/628a/648a btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none encoding: 01 11bb bfff ffff description: if bit 'b' in register 'f' is '1' then the next instruction is skipped. if bit 'b' is '1', then the next instruc- tion fetched during the current instruction execution, is discarded and a nop is executed instead, making this a two-cycle instruc- tion. words: 1 cycles: 1(2) example here false true btfss goto    reg1 process_code before instruction pc = address here after instruction if flag<1> = 0, pc = address false if flag<1> = 1, pc = address true call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none encoding: 10 0kkk kkkk kkkk description: call subroutine. first, return address (pc+1) is pushed onto the stack. the eleven bit imme- diate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. words: 1 cycles: 2 example here call there before instruction pc = address here after instruction pc = address there tos = address here+1 clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z encoding: 00 0001 1fff ffff description: the contents of register 'f' are cleared and the z bit is set. words: 1 cycles: 1 example clrf reg1 before instruction reg1 = 0x5a after instruction reg1 = 0x00 z=1
pic16f627a/628a/648a ds40044a-page 116 preliminary ? 2002 microchip technology inc. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z encoding: 00 0001 0000 0011 description: w register is cleared. zero bit (z) is set. words: 1 cycles: 1 example clrw before instruction w = 0x5a after instruction w = 0x00 z=1 clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd encoding: 00 0000 0110 0100 description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. words: 1 cycles: 1 example clrwdt before instruction wdt counter = ? after instruction wdt counter = 0x00 wdt prescaler = 0 to =1 pd =1 comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f ) (dest) status affected: z encoding: 00 1001 dfff ffff description: the contents of register 'f' are complemented. if 'd' is 0 the result is stored in w. if 'd' is 1 the result is stored back in register 'f'. words: 1 cycles: 1 example comf reg1, 0 before instruction reg1 = 0x13 after instruction reg1 = 0x13 w = 0xec decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (dest) status affected: z encoding: 00 0011 dfff ffff description: decrement register 'f'. if 'd' is 0 the result is stored in the w reg- ister. if 'd' is 1 the result is stored back in register 'f'. words: 1 cycles: 1 example decf cnt, 1 before instruction cnt = 0x01 z=0 after instruction cnt = 0x00 z=1
? 2002 microchip technology inc. preliminary ds40044a-page 117 pic16f627a/628a/648a decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (dest); skip if result = 0 status affected: none encoding: 00 1011 dfff ffff description: the contents of register 'f' are decremented. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is placed back in register 'f'. if the result is 0, the next instruc- tion, which is already fetched, is discarded. a nop is executed instead making it a two-cycle instruction. words: 1 cycles: 1(2) example here decfsz reg1, 1 goto loop continue    before instruction pc = address here after instruction reg1 = reg1 - 1 if reg1 = 0, pc = address continue if reg1 0, pc = address here+1 goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none encoding: 10 1kkk kkkk kkkk description: goto is an unconditional branch. the eleven-bit immedi- ate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. words: 1 cycles: 2 example goto there after instruction pc = address there
pic16f627a/628a/648a ds40044a-page 118 preliminary ? 2002 microchip technology inc. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (dest) status affected: z encoding: 00 1010 dfff ffff description: the contents of register 'f' are incremented. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is placed back in register 'f'. words: 1 cycles: 1 example incf reg1, 1 before instruction reg1 = 0xff z=0 after instruction reg1 = 0x00 z=1 incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (dest), skip if result = 0 status affected: none encoding: 00 1111 dfff ffff description: the contents of register 'f' are incremented. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is placed back in register 'f'. if the result is 0, the next instruc- tion, which is already fetched, is discarded. a nop is executed instead making it a two-cycle instruction. words: 1 cycles: 1(2) example here incfsz reg1, 1 goto loop continue    before instruction pc = address here after instruction reg1 = reg1 + 1 if cnt = 0, pc = address continue if reg1 0, pc = address here +1
? 2002 microchip technology inc. preliminary ds40044a-page 119 pic16f627a/628a/648a iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z encoding: 11 1000 kkkk kkkk description: the contents of the w register is or?ed with the eight bit literal 'k'. the result is placed in the w register. words: 1 cycles: 1 example iorlw 0x35 before instruction w=0x9a after instruction w=0xbf z=0 iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (dest) status affected: z encoding: 00 0100 dfff ffff description: inclusive or the w register with register 'f'. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is placed back in register 'f'. words: 1 cycles: 1 example iorwf reg1, 0 before instruction reg1 = 0x13 w = 0x91 after instruction reg1 = 0x13 w = 0x93 z=1 movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none encoding: 11 00xx kkkk kkkk description: the eight bit literal 'k' is loaded into w register. the don?t cares will assemble as 0?s. words: 1 cycles: 1 example movlw 0x5a after instruction w=0x5a movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (dest) status affected: z encoding: 00 1000 dfff ffff description: the contents of register f is moved to a destination depen- dent upon the status of d. if d = 0, destination is w register. if d = 1, the destination is file regis- ter f itself. d = 1 is useful to test a file register since status flag z is affected. words: 1 cycles: 1 example movf reg1, 0 after instruction w = value in reg1 register z= 1
pic16f627a/628a/648a ds40044a-page 120 preliminary ? 2002 microchip technology inc. movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none encoding: 00 0000 1fff ffff description: move data from w register to regis- ter 'f' . words: 1 cycles: 1 example movwf reg1 before instruction reg1 = 0xff w = 0x4f after instruction reg1 = 0x4f w = 0x4f nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none encoding: 00 0000 0xx0 0000 description: no operation. words: 1 cycles: 1 example nop option load option register syntax: [ label ] option operands: none operation: (w) option status affected: none encoding: 00 0000 0110 0010 description: the contents of the w register are loaded in the option register. this instruction is supported for code compatibility with pic16c5x products. since option is a readable/writable register, the user can directly address it. using only register instruction such as movwf. words: 1 cycles: 1 example to maintain upward compatibil- ity with future picmicro ? prod- ucts, do not use this instruction. retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none encoding: 00 0000 0000 1001 description: return from interrupt. stack is poped and top of stack (tos) is loaded in the pc. interrupts are enabled by setting global interrupt enable bit, gie (intcon<7>). this is a two- cycle instruction. words: 1 cycles: 2 example retfie after interrupt pc = tos gie = 1
? 2002 microchip technology inc. preliminary ds40044a-page 121 pic16f627a/628a/648a retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none encoding: 11 01xx kkkk kkkk description: the w register is loaded with the eight bit literal 'k'. the pro- gram counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. words: 1 cycles: 2 example table call table;w contains table ;offset value  ;w now has table value   addwf pc;w = offset retlw k1;begin table retlw k2;    retlw kn; end of table before instruction w = 0x07 after instruction w = value of k8 return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none encoding: 00 0000 0000 1000 description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction. words: 1 cycles: 2 example return after interrupt pc = tos rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c encoding: 00 1101 dfff ffff description: the contents of register 'f' are rotated one bit to the left through the carry flag. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is stored back in reg- ister 'f'. words: 1 cycles: 1 example rlf reg1, 0 before instruction reg1 =1110 0110 c =0 after instruction reg1 =1110 0110 w = 1100 1100 c =1 register f c
pic16f627a/628a/648a ds40044a-page 122 preliminary ? 2002 microchip technology inc. rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c encoding: 00 1100 dfff ffff description: the contents of register 'f' are rotated one bit to the right through the carry flag. if 'd' is 0 the result is placed in the w reg- ister. if 'd' is 1 the result is placed back in register 'f'. words: 1 cycles: 1 example rrf reg1, 0 before instruction reg1 = 1110 0110 c =0 after instruction reg1 = 1110 0110 w = 0111 0011 c =0 sleep syntax: [ labe l ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd encoding: 00 0000 0110 0011 description: the power-down status bit, pd is cleared. time out sta- tus bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscilla- tor stopped. see section 14.8 for more details. words: 1 cycles: 1 example: sleep register f c sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z encoding: 11 110x kkkk kkkk description: the w register is subtracted (2?s complement method) from the eight bit literal 'k'. the result is placed in the w register. words: 1 cycles: 1 example 1: sublw 0x02 before instruction w=1 c=? after instruction w= 1 c = 1; result is positive example 2: before instruction w= 2 c=? after instruction w= 0 c = 1; result is zero example 3: before instruction w= 3 c= ? after instruction w= 0xff c = 0; result is negative
? 2002 microchip technology inc. preliminary ds40044a-page 123 pic16f627a/628a/648a subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) - (w) ( dest) status affected: c, dc, z encoding: 00 0010 dfff ffff description: subtract (2?s complement method) w register from register 'f'. if 'd' is 0 the result is stored in the w register. if 'd' is 1 the result is stored back in register 'f'. words: 1 cycles: 1 example 1: subwf reg1, 1 before instruction reg1 = 3 w=2 c=? after instruction reg1 = 1 w=2 c = 1; result is positive z = dc = 1 example 2: before instruction reg1 = 2 w=2 c=? after instruction reg1 = 0 w=2 c = 1; result is zero z = dc = 1 example 3: before instruction reg1 = 1 w=2 c=? after instruction reg1 = 0xff w=2 c = 0; result is negative z = dc = 0 swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (dest<7:4>), (f<7:4>) (dest<3:0>) status affected: none encoding: 00 1110 dfff ffff description: the upper and lower nibbles of register 'f' are exchanged. if 'd' is 0 the result is placed in w regis- ter. if 'd' is 1 the result is placed in register 'f'. words: 1 cycles: 1 example swapf reg1, 0 before instruction reg1 = 0xa5 after instruction reg1 = 0xa5 w = 0x5a tris load tris register syntax: [ label ] tris f operands: 5 f 7 operation: (w) tris register f; status affected: none encoding: 00 0000 0110 0fff description: the instruction is supported for code compatibility with the pic16c5x products. since tris registers are readable and writ- able, the user can directly address them. words: 1 cycles: 1 example to maintain upward compatibil- ity with future picmicro ? prod- ucts, do not use this instruction.
pic16f627a/628a/648a ds40044a-page 124 preliminary ? 2002 microchip technology inc. xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z encoding: 11 1010 kkkk kkkk description: the contents of the w register are xor?ed with the eight bit lit- eral 'k'. the result is placed in the w register. words: 1 cycles: 1 example: xorlw 0xaf before instruction w = 0xb5 after instruction w = 0x1a xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( dest) status affected: z encoding: 00 0110 dfff ffff description: exclusive or the contents of the w register with register 'f'. if 'd' is 0 the result is stored in the w reg- ister. if 'd' is 1 the result is stored back in register 'f'. words: 1 cycles: 1 example xorwf reg1, 1 before instruction reg1 = 0xaf w=0xb5 after instruction reg1 = 0x1a w = 0xb5
? 2002 microchip technology inc. preliminary ds40044a-page 125 pic16f627a/628a/648a 16.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools:  integrated development environment - mplab ? ide software  assemblers/compilers/linkers -mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian  simulators - mplab sim software simulator  emulators - mplab ice 2000 in-circuit emulator - icepic? in-circuit emulator  in-circuit debugger - mplab icd  device programmers -pro mate ? ii universal device programmer - picstart ? plus entry-level development programmer  low cost demonstration boards - picdem tm 1 demonstration board - picdem 2 demonstration board - picdem 3 demonstration board - picdem 17 demonstration board -k ee l oq ? demonstration board 16.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8-bit microcon- troller market. the mplab ide is a windows ? -based application that contains:  an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately)  a full-featured editor  a project manager  customizable toolbar and key mapping  a status bar  on-line help the mplab ide allows you to:  edit your source files (either assembly or ?c?)  one touch assemble (or compile) and download to picmicro emulator and simulator tools (auto- matically updates all project information)  debug using: - source files - absolute listing file - machine code the ability to use mplab ide with multiple debugging tools allows users to easily switch from the cost- effective simulator to a full-featured emulator with minimal retraining. 16.2 mpasm assembler the mpasm assembler is a full-featured universal macro assembler for all picmicro mcu?s. the mpasm assembler has a command line interface and a windows shell. it can be used as a stand-alone application on a windows 3.x or greater system, or it can be used through mplab ide. the mpasm assem- bler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, an abso- lute lst file that contains source lines and generated machine code, and a cod file for debugging. the mpasm assembler features include:  integration into mplab ide projects.  user-defined macros to streamline assembly code.  conditional assembly for multi-purpose source files.  directives that allow complete control over the assembly process. 16.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi ?c? compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers, respectively. these compilers provide powerful integration capabilities and ease of use not found with other compilers. for easier source level debugging, the compilers pro- vide symbol information that is compatible with the mplab ide memory display.
pic16f627a/628a/648a ds40044a-page 126 preliminary ? 2002 microchip technology inc. 16.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can also link relocatable objects from pre-compiled libraries, using directives from a linker script. the mplib object librarian is a librarian for pre- compiled code to be used with the mplink object linker. when a routine from a library is called from another source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the mplib object librarian manages the creation and modification of library files. the mplink object linker features include:  integration with mpasm assembler and mplab c17 and mplab c18 c compilers.  allows all memory areas to be defined as sections to provide link-time flexibility. the mplib object librarian features include:  easier linking because single libraries can be included instead of many smaller files.  helps keep code maintainable by grouping related modules together.  allows libraries to be created and modules to be added, listed, replaced, deleted or extracted. 16.5 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc-hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user-defined key press, to any of the pins. the execution can be performed in single step, execute until break, or trace mode. the mplab sim simulator fully supports symbolic debug- ging using the mplab c17 and the mplab c18 c com- pilers and the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent multi- project software development tool. 16.6 mplab ice high performance universal in-circuit emulator with mplab ide the mplab ice universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers (mcus). software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment (ide), which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice in-circuit emulator system has been designed as a real-time emulation system, with advanced features that are generally found on more expensive development tools. the pc platform and microsoft ? windows environment were chosen to best make these features available to you, the end user. 16.7 icepic in-circuit emulator the icepic low cost, in-circuit emulator is a solution for the microchip technology pic16c5x, pic16c6x, pic16c7x and pic16cxxx families of 8-bit one- time-programmable (otp) microcontrollers. the mod- ular system can support different subsets of pic16c5x or pic16cxxx products through the use of inter- changeable personality modules, or daughter boards. the emulator is capable of emulating without target application circuitry being present.
? 2002 microchip technology inc. preliminary ds40044a-page 127 pic16f627a/628a/648a 16.8 mplab icd in-circuit debugger microchip's in-circuit debugger, mplab icd, is a pow- erful, low cost, run-time development tool. this tool is based on the flash picmicro mcus and can be used to develop for this and other picmicro microcontrollers. the mplab icd utilizes the in-circuit debugging capa- bility built into the flash devices. this feature, along with microchip's in-circuit serial programming tm proto- col, offers cost-effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by watch- ing variables, single-stepping and setting break points. running at full speed enables testing hardware in real- time. 16.9 pro mate ii universal device programmer the pro mate ii universal device programmer is a full-featured programmer, capable of operating in stand-alone mode, as well as pc-hosted mode. the pro mate ii device programmer is ce compliant. the pro mate ii device programmer has program- mable v dd and v pp supplies, which allow it to verify programmed memory at v dd min and v dd max for max- imum reliability. it has an lcd display for instructions and error messages, keys to enter commands and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify, or program picmicro devices. it can also set code protection in this mode. 16.10 picstart plus entry level development programmer the picstart plus development programmer is an easy-to-use, low cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer sup- ports all picmicro devices with up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 16.11 picdem 1 low cost picmicro demonstration board the picdem 1 demonstration board is a simple board which demonstrates the capabilities of several of microchip?s microcontrollers. the microcontrollers sup- ported are: pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the user can program the sample microcon- trollers provided with the picdem 1 demonstration board on a pro mate ii device programmer, or a picstart plus development programmer, and easily test firmware. the user can also connect the picdem 1 demonstration board to the mplab ice in- circuit emulator and download the firmware to the emu- lator for testing. a prototype area is available for the user to build some additional hardware and connect it to the microcontroller socket(s). some of the features include an rs-232 interface, a potentiometer for simu- lated analog input, push button switches and eight leds connected to portb. 16.12 picdem 2 low cost pic16cxx demonstration board the picdem 2 demonstration board is a simple dem- onstration board that supports the pic16c62, pic16c64, pic16c65, pic16c73 and pic16c74 microcontrollers. all the necessary hardware and soft- ware is included to run the basic demonstration pro- grams. the user can program the sample microcontrollers provided with the picdem 2 demon- stration board on a pro mate ii device programmer, or a picstart plus development programmer, and easily test firmware. the mplab ice in-circuit emula- tor may also be used with the picdem 2 demonstration board to test firmware. a prototype area has been pro- vided to the user for adding additional hardware and connecting it to the microcontroller socket(s). some of the features include a rs-232 interface, push button switches, a potentiometer for simulated analog input, a serial eeprom to demonstrate usage of the i 2 c tm bus and separate headers for connection to an lcd module and a keypad.
pic16f627a/628a/648a ds40044a-page 128 preliminary ? 2002 microchip technology inc. 16.13 picdem 3 low cost pic16cxxx demonstration board the picdem 3 demonstration board is a simple dem- onstration board that supports the pic16c923 and pic16c924 in the plcc package. it will also support future 44-pin plcc microcontrollers with an lcd mod- ule. all the necessary hardware and software is included to run the basic demonstration programs. the user can program the sample microcontrollers pro- vided with the picdem 3 demonstration board on a pro mate ii device programmer, or a picstart plus development programmer with an adapter socket, and easily test firmware. the mplab ice in-circuit emula- tor may also be used with the picdem 3 demonstration board to test firmware. a prototype area has been pro- vided to the user for adding hardware and connecting it to the microcontroller socket(s). some of the features include a rs-232 interface, push button switches, a potentiometer for simulated analog input, a thermistor and separate headers for connection to an external lcd module and a keypad. also provided on the picdem 3 demonstration board is a lcd panel, with 4 commons and 12 segments, that is capable of display- ing time, temperature and day of the week. the picdem 3 demonstration board provides an additional rs-232 interface and windows software for showing the demultiplexed lcd signals on a pc. a simple serial interface allows the user to construct a hardware demultiplexer for the lcd signals. 16.14 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. all neces- sary hardware is included to run basic demo programs, which are supplied on a 3.5-inch disk. a programmed sample is included and the user may erase it and program it with the other sample programs using the pro mate ii device programmer, or the picstart plus development programmer, and easily debug and test the sample code. in addition, the picdem 17 dem- onstration board supports downloading of programs to and executing out of external flash memory on board. the picdem 17 demonstration board is also usable with the mplab ice in-circuit emulator, or the picmaster emulator and all of the sample programs can be run and modified using either emulator. addition- ally, a generous prototype area is available for user hardware. 16.15 k ee l oq evaluation and programming tools k ee l oq evaluation and programming tools support microchip?s hcs secure data products. the hcs eval- uation kit includes a lcd display to show changing codes, a decoder to decode transmissions and a pro- gramming interface to program test transmitters.
? 2002 microchip technology inc. preliminary ds40044a-page 129 pic16f627a/628a/648a table 16-1: development tools from microchip pic12cxxx pic14000 pic16c5x pic16c6x pic16cxxx pic16f62x pic16c7x pic16c7xx pic16c8x pic16f8xx pic16c9xx pic17c4x pic17c7xx pic18cxx2 pic18fxxx 24cxx/ 25cxx/ 93cxx hcsxxx mcrfxxx mcp2510 software tools mplab ? integrated development environment  mplab ? c17 c compiler  mplab ? c18 c compiler  mpasm tm assembler/ mplink tm object linker    emulators mplab ? ice in-circuit emulator    **  icepic tm in-circuit emulator     debugger mplab ? icd in-circuit debugger  *  *  programmers picstart ? plus entry level development programmer    **  pro mate ? ii universal device programmer    **    demo boards and eval kits picdem tm 1 demonstration board  ?  picdem tm 2 demonstration board  ?  ?  picdem tm 3 demonstration board  picdem tm 14a demonstration board  picdem tm 17 demonstration board  k ee l oq ? evaluation kit  k ee l oq ? transponder kit  microid tm programmer?s kit  125 khz microid tm developer?s kit  125 khz anticollision microid tm developer?s kit  13.56 mhz anticollision microid tm developer?s kit  mcp2510 can developer?s kit  * contact the microchip technology inc. web site at www.microchip.com for information on how to use the mplab ? icd in-circuit debugger (dv164001) with pic16c62, 63, 64, 65, 72, 73, 74, 76, 77. ** contact microchip technology inc. for availability date. ? development tool is available on select devices.
pic16f627a/628a/648a ds40044a-page 130 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 131 pic16f627a/628a/648a 17.0 electrical specifications absolute maximum ratings? ambient temperature under bias................................................................................................. ................ -40 to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on v dd with respect to v ss ............................................................................................................ -0.3 to +6.5v voltage on mclr and ra4 with respect to v ss ............................................................................................-0.3 to +14v voltage on all other pins with respect to v ss ....................................................................................-0.3v to v dd + 0.3v total power dissipation (1) ............................................................................................................................... ......800 mw maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ..................................................................................................................... 20 ma output clamp current, i ok (vo < 0 or vo >v dd ) ............................................................................................................... 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by porta and portb (combined)................................................................................200 ma maximum current sourced by porta and portb (combined).......................................................................... .200 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd - i oh } + {(v dd -v oh ) x i oh } + (v o l x i ol ) ? notice : stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability. note: voltage spikes below v ss at the mclr pin, inducing currents greater than 80 ma, may cause latchup. thus, a series resistor of 50-100 ? should be used when applying a ?low? level to the mclr pin rather than pulling this pin directly to v ss .
pic16f627a/628a/648a ds40044a-page 132 preliminary ? 2002 microchip technology inc. figure 17-1: pic16f627a/628a/648a voltage-frequency graph, -40 c ta +125 c figure 17-2: pic16lf627a/628a/648a voltage-frequency graph, -40 c ta +85 c 6.0 2.5 4.0 3.0 0 3.5 4.5 5.0 5.5 410 frequency (mhz) v dd 20 (volts ) 25 note: the shaded region indicates the permissible combinations of voltage and frequency. 6.0 2.5 4.0 3.0 0 3.5 4.5 5.0 5.5 410 frequency (mhz) v dd 20 (volts) 25 2.0 note: the shaded region indicates the permissible combinations of voltage and frequency.
? 2002 microchip technology inc. preliminary ds40044a-page 133 pic16f627a/628a/648a 17.1 dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) pic16lf627a/628a/648a (industrial) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial pic16f627a/628a/648a (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial and -40 c ta +125 c for extended param no. sym characteristic/device min typ? max units conditions v dd supply voltage d001 pic16lf627a/628a/648a 2.0 ? 5.5 v pic16f627a/628a/648a 3.0 ? 5.5 v d002 v dr ram data retention voltage (1) ? 1.5* ? v device in sleep mode d003 v por v dd start voltage to ensure power-on reset ?v ss ? v see section 14.4 on power-on reset for details d004 s vdd v dd rise rate to ensure power-on reset 0.05* ? ? v/ms see section 14.4 on power-on reset for details d005 v bor brown-out reset voltage 3.65 3.65 4.0 4.0 4.35 4.4 v v boren configuration bit is set boren configuration bit is set, extended legend: rows with standard voltage device data only are shaded for improved readability. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0 v, 25 c, unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered in sleep mode without losing ram data.
pic16f627a/628a/648a ds40044a-page 134 preliminary ? 2002 microchip technology inc. 17.2 dc characteristics: pic16f627a/628a/648a (industrial) pic16lf627a/628a/648a (industrial) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial param no. lf and f device characteristics min? typ max units conditions v dd note supply voltage (v dd ) d001 lf 2.0 ? 5.5 v ? lf/f 3.0 ? 5.5 v ? power-down base current (i pd ) d020 lf ? 0.1 0.80 a 2.0 wdt, bor, comparators, v ref , and t1osc: disabled lf/f ? 0.1 0.85 a3.0 ? 0.2 0.95 a5.0 peripheral module current ( ? i mod ) (1) d021 lf ?12.0 a 2.0 wdt current lf/f ?23.4 a3.0 ? 9 12.5 a5.0 d022 lf/f ?32tbd a 4.5 bor current ?33tbd a5.0 d023 lf ?15tbd a 2.0 comparator current lf/f ?27tbd a3.0 ?49tbd a5.0 d024 lf ?34tbd a2.0v ref current lf/f ?50tbd a3.0 ?80tbd a5.0 d025 lf ?1.22.0 a 2.0 t1o sc current lf/f ?1.32.2 a3.0 ?1.82.9 a5.0 supply current (i dd ) d010 lf ?1215 a2.0f osc = 32 khz lp oscillator mode lf/f ?2125 a3.0 ?3848 a5.0 d011 lf ? 120 160 a2.0f osc = 1 mhz xt oscillator mode lf/f ? 180 250 a3.0 ? 290 370 a5.0 d012 lf ? 240 300 a2.0f osc = 4 mhz xt oscillator mode lf/f ? 370 470 a3.0 ? 670 780 a5.0 d013 lf/f ?2.62.9 ma 4.5f osc = 20 mhz hs oscillator mode ?33.3ma5.0 note 1: the ? ? ? current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. max values should be used when calculating total current consumption.
? 2002 microchip technology inc. preliminary ds40044a-page 135 pic16f627a/628a/648a 17.3 dc characteristics: pic16f627a/628a/648a (extended) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +125 c for extended param no. device characteristics min? typ max units conditions v dd note supply voltage (v dd ) d001 ? 3.0 ? 5.5 v ? power-down base current (i pd ) d020e ? ?0.1tbd a 3.0 wdt, bor, comparators, v ref , and t1osc: disabled ?0.2tbd a5.0 peripheral module current ( ? i mod ) (1) d021e ? ?2tbd a 3.0 wdt current ?9tbd a5.0 d022e ? ?32tbd a 4.5 bor current ?33tbd a5.0 d023e ? ?27tbd a 3.0 comparator current ?49tbd a5.0 d024e ? ?50tbd a3.0v ref current ?83tbd a5.0 d025e ? ?1.3tbd a 3.0 t1o sc current ?1.8tbd a5.0 supply current (i dd ) d010e ? ?21tbd a3.0f osc = 32 khz lp oscillator mode ?38tbd a5.0 d011e ? ? 182 tbd a3.0f osc = 1 mhz xt oscillator mode ? 293 tbd a5.0 d012e ? ? 371 tbd a3.0f osc = 4 mhz xt oscillator mode ? 668 tbd a5.0 d013e ? ? 2.6 tbd ma 4.5 f osc = 20 mhz hs oscillator mode ?3tbdma5.0 note 1: the ? ? ? current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. max values should be used when calculating total current consumption.
pic16f627a/628a/648a ds40044a-page 136 preliminary ? 2002 microchip technology inc. 17.4 dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ta +85c for industrial and -40c ta +125c for extended operating voltage v dd range as described in dc spec table 17-2 and table 17-3 param. no. sym characteristic/device min typ? max unit conditions v il input low voltage d030 d031 d032 d033 i/o ports with ttl buffer with schmitt trigger input (4) mclr , ra4/t0cki,osc1 (in rc mode) osc1 (in hs) osc1 (in lp and xt) v ss v ss v ss v ss v ss v ss ? ? ? ? ? ? 0.8 0.15 v dd 0.2 v dd 0.2 v dd 0.3 v dd 0.8 v v v v v v v dd = 4.5v to 5.5v otherwise (note1) v ih input high voltage d040 d041 d042 d043 d043a i/o ports with ttl buffer with schmitt trigger input (4) mclr ra4/t0cki osc1 (xt, hs and lp) osc1 (in rc mode) 2.0 v .25 v dd + 0.8 v 0.8 v dd 0.8 v dd 0.7 v dd 0.9 v dd ? ? ? ? ? ? v dd v dd v dd v dd v dd v dd v v v v v v v dd = 4.5v to 5.5v otherwise (note1) d070 i purb portb weak pull-up current 50 200 400 av dd = 5.0v, v pin = v ss i il input leakage current (2), (3) d060 d061 d063 i/o ports (except porta) porta (4) ra4/t0cki osc1, mclr ? ? ? ? ? ? ? ? 1.0 0.5 1.0 5.0 a a a a v ss v pin v dd , pin at hi-impedance v ss v pin v dd , pin at hi-impedance v ss v pin v dd v ss v pin v dd , xt, hs and lp osc configuration v ol output low voltage d080 i/o ports (4) ? ? ? ? 0.6 0.6 v v i ol =8.5 ma, v dd =4.5 v, -40 to +85 c i ol =7.0 ma, v dd =4.5 v, +85 to +125 c v oh output high voltage (3) d090 i/o ports (except ra4 (4) v dd -0.7 v dd -0.7 ? ? ? ? v v i oh =-3.0 ma, v dd =4.5 v, -40 to +85 c i oh =-2.5 ma, v dd =4.5 v, +85 to +125 c d150 v od open-drain high voltage ? ? 8.5* v ra4 pin pic16f627a/628a/648a, pic16lf627a/628a/648a capacitive loading specs on output pins d100* d101* cosc2 cio osc2 pin all i/o pins/osc2 (in rc mode) ? ? ? ? 15 50 pf pf in xt, hs and lp modes when external clock used to drive osc1. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1 pin is a schmitt trigger input. it is not recommended that the pic16f627a/628a/648a be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as coming out of the pin. 4: includes osc1 and osc2 when configured as i/o pins, clkin, or clkout.
? 2002 microchip technology inc. preliminary ds40044a-page 137 pic16f627a/628a/648a table 17-1: dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ta +85c for industrial and -40c ta +125c for extended operating voltage v dd range as described in dc spec table 17-2 and table 17-3 parameter no. sym characteristic min typ? max units conditions data eeprom memory d120 d120a d121 d122 d123 d124 e d e d v drw t dew t retd t ref endurance endurance v dd for read/write erase/write cycle time characteristic retention number of total erase/write cycles before refresh (1) 100k 10k v min ? 100 1m 1m 100k ? 4 ? 10m ? 5.5 8 * ? ? e/w e/w v ms year e/w -40 c t a 85c 85c t a 125c v min = minimum operating voltage provided no other specifications are violated -40 c to +85c program flash memory d130 d130a d131 d132 d132a d133 d133a d134 e p e p v pr v ie v pew t ie t pew t retp endurance endurance v dd for read v dd for block erase v dd for write block erase cycle time write cycle time characteristic retention 10k 1000 v min 4.5 v min ? ? 100 100k 10k ? ? ? 4 2 ? ? ? 5.5 5.5 5.5 8 * 4 * ? e/w e/w v v v ms ms year -40 c t a 85c 85c t a 125c v min = minimum operating voltage v min = minimum operating voltage v dd > 4.5v provided no other specifications are violated * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0 v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: refer to section 13.7 for a more detailed discussion on data eeprom endurance.
pic16f627a/628a/648a ds40044a-page 138 preliminary ? 2002 microchip technology inc. table 17-2: comparator specifications table 17-3: voltage reference specifications operating conditions: 2.0v < v dd < 5.5v, -40c < t a < +125c, unless otherwise stated. param no. characteristics sym min typ max units comments d300 input offset voltage v ioff ? 5.0 10 mv d301 input common mode voltage v icm 0?v dd - 1.5* v d302 common mode rejection ratio cmrr 55* ? ? db d303 response time (1) t resp ? ? ? 300 400 400 400* 600* 600* ns ns ns v dd = 3.0v to 5.5v -40 to +85c v dd = 3.0v to 5.5v -85 to +125c v dd = 2.0v to 3.0v -40 to +85c d304 comparator mode change to output valid t mc 2 ov ? 300 10* s * these parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd - 1.5)/2 while the other input transitions from v ss to v dd . operating conditions: 2.0v < v dd < 5.5v, -40 c < t a < +125 c, unless otherwise stated. spec no. characteristics sym min typ max units comments d310 resolution v res ??v dd /24 v dd /32 lsb lsb low range (vrr = 1) high range (vrr = 0) d311 absolute accuracy vr aa ? ? ? ? 1/4 (2) * 1/2 (2) * lsb lsb low range (vrr = 1) high range (vrr = 0) d312 unit resistor value (r) vr ur ?2k*? ? d313 settling time (1) t set ? ? 10* s * these parameters are characterized but not tested. note 1: settling time measured while vrr = 1 and vr<3:0> transitions from 0000 to 1111 . 2: when v dd is between 2.0v and 3.0v the v ref output voltage levels on ra2 descirbed by the equa- tion:[v dd /2 (3-v dd )/2] may cause the absolute accuracy (vr aa ) of the v ref output signal on ra2 to be greater than the stated max.
? 2002 microchip technology inc. preliminary ds40044a-page 139 pic16f627a/628a/648a 17.5 timing parameter symbology the timing parameter symbols have been created with one of the following formats: figure 17-3: load conditions 1. tpps2pps 2. tpps t f frequency t time lowercase subscripts (pp) and their meanings: pp ck clkout osc osc1 io i/o port t0 t0cki mc mclr uppercase letters and their meanings: s f fall p period h high r rise i invalid (hi-impedance) v valid l low z hi-impedance v dd /2 cl rl pin pin v ss v ss cl r l =464 ? c l = 50 pf for all pins except osc2 15 pf for osc2 output load condition 1 load condition 2
pic16f627a/628a/648a ds40044a-page 140 preliminary ? 2002 microchip technology inc. 17.6 timing diagrams and specifications figure 17-4: external clock timing table 17-4: external clock timing requirements parameter no. sym characteristic min typ? max units conditions fosc external clkin frequency (1) dc ? 4 mhz xt and rc osc mode, v dd = 5.0 v dc ? 20 mhz hs osc mode dc ? 200 khz lp osc mode oscillator frequency (1) ? ? 4 mhz rc osc mode, v dd = 5.0v 0.1 ? 4 mhz xt osc mode 1 ? ? ? 20 200 mhz khz hs osc mode lp osc mode ? 4 ? mhz intosc mode (fast) ? 37 ? khz intosc mode (slow) 1 tosc external clkin period (1) 250 ? ? ns xt and rc osc mode 50 ? ? ns hs osc mode 5?? s lp osc mode oscillator period (1) 250 ? ? ns rc osc mode 250 ? 10,000 ns xt osc mode 50 ? 1,000 ns hs osc mode 5?? s lp osc mode ? 250 ? ns intosc mode (fast) ?27? s intosc mode (slow) 2 tcy instruction cycle time 1.0 t cy dc ns t cy = 4/f osc 3 tosl, to s h external clkin (osc1) high external clkin low 100* ? ? ns xt oscillator, t osc l/h duty cycle 4 rc external biased rc fre- quency 10 khz* ? 4 mhz ? v dd = 5.0v * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note: instruction cycle period (tcy) equals four times the input oscillator time-based period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator oper- ation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to the osc1 pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. osc1 clkout q4 q1 q2 q3 q4 q1 133 44 2
? 2002 microchip technology inc. preliminary ds40044a-page 141 pic16f627a/628a/648a table 17-5: precision internal oscillator parameters figure 17-5: clkout and i/o timing table 17-6: clkout and i/o timing requirements parameter no. sym characteristic min typ max units conditions f10 f iosc oscillator center frequency ?4?mhz f13 ? i osc oscillator stability (jitter) ?? 1%v dd = 3.5 v, 25 c ?? 2 % 2.0 v v dd 5.5v 0 c t a +85 c ?? 5 % 2.0 v v dd 5.5v -40 c t a +85 c (ind) -40 c t a +125 c (ext) f14 t ioscst oscillator wake-up from sleep start-up time ?6tbd sv dd = 2.0v, -40 c to +85 c ?4tbd sv dd = 3.0v, -40 c to +85 c ?3tbd sv dd = 5.0v, -40 c to +85 c parameter no. sym characteristic min typ? max units 10 tosh2ckl osc1 to clkout pic16f62x ? 75 200* ns 10a pic16lf62x ? ? 400* ns 11 tosh2ckh osc1 to clkout pic16f62x ? 75 200* ns 11a pic16lf62x ? ? 400* ns 12 tckr clkout rise time pic16f62x ? 35 100* ns 12a pic16lf62x ? ? 200* ns 13 tckf clkout fall time pic16f62x ? 35 100* ns 13a pic16lf62x ? ? 200* ns 14 tckl2iov clkout to port out valid ? ? 20* ns 15 tiov2ckh port in valid before pic16f62x tosc+200 ns* ? ? ns 18 tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) 100* 200* ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. osc1 clkout i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 22 23 19 18 15 11 12 16 old value new value
pic16f627a/628a/648a ds40044a-page 142 preliminary ? 2002 microchip technology inc. figure 17-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 17-7: brown-out detect timing clkout pic16lf62x tosc+400 ns* ? ? ns 16 tckh2ioi port in hold after clkout 0 ? ? ns 17 tosh2iov osc1 (q1 cycle) to pic16f62x ? 50 150* ns port out valid pic16lf62x ? ? 300* ns parameter no. sym characteristic min typ? max units 18 tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) 100* 200* ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. v dd mclr internal por pwrt time out ost time out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 v dd v bor 35
? 2002 microchip technology inc. preliminary ds40044a-page 143 pic16f627a/628a/648a table 17-7: reset, watchdog timer, oscillator start-up timer and power-up timer requirements figure 17-8: timer0 and timer1 external clock timings parameter no. sym characteristic min typ? max units conditions 30 tmcl mclr pulse width (low) 2000 tbd ? tbd ? tbd ns ms v dd = 5v, -40c to +85c extended temperature 31 twdt watchdog timer time out period (no prescaler) 7* tbd 18 tbd 33* tbd ms ms v dd = 5v, -40c to +85c extended temperature 32 tost oscillation start-up timer period ? 1024t osc ??t osc = osc1 period 33 tpwrt power-up timer period 28* tbd 72 tbd 132* tbd ms ms v dd = 5v, -40c to +85c extended temperature 34 tioz i/o hi-impedance from mclr low or watchdog timer reset ? ? 2.0* s 35 t bor brown-out reset pulse width 100* ? ? sv dd v bor (d005) * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. 46 47 45 48 41 42 40 ra4/t0cki rb6/t1oso/t1cki tmr0 or tmr1
pic16f627a/628a/648a ds40044a-page 144 preliminary ? 2002 microchip technology inc. table 17-9: timer0 and timer1 external clock requirements param no. sym characteristic min typ? max units conditions 40 tt0h t0cki high pulse width no prescaler 0.5t cy + 20* ? ? ns with prescaler 10* ? ? ns 41 tt0l t0cki low pulse width no prescaler 0.5t cy + 20* ? ? ns with prescaler 10* ? ? ns 42 tt0p t0cki period greater of: t cy + 40 * n ? ? ns n = prescale value (2, 4, ..., 256) 45 tt1h t1cki high time synchronous, no prescaler 0.5t cy + 20* ? ? ns synchronous, with prescaler pic16f62x 15* ? ? ns pic16lf62x 25* ? ? ns asynchronous pic16f62x 30* ? ? ns pic16lf62x 50* ? ? ns 46 tt1l t1cki low time synchronous, no prescaler 0.5t cy + 20* ? ? ns synchronous, with prescaler pic16f62x 15* ? ? ns pic16lf62x 25* ? ? ns asynchronous pic16f62x 30* ? ? ns pic16lf62x 50* ? ? ns 47 tt1p t1cki input period synchronous pic16f62x greater of: t cy + 40 * n ? ? ns n = prescale value (1, 2, 4, 8) pic16lf62x greater of: t cy + 40 * n ??? asynchronous pic16f62x 60* ? ? ns pic16lf62x 100* ? ? ns ft1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) ? 32.7 (1) ?khz 48 tckezt mr1 delay from external clock edge to timer increment 2tosc ? 7tosc ? * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this oscillator is intended to work only with 32.768 khz watch crystals and their manufactured tolerances. higher value crystal frequencies may not be compatible with this crystal driver.
? 2002 microchip technology inc. preliminary ds40044a-page 145 pic16f627a/628a/648a figure 17-10: capture/compare/pwm timings table 17-8: capture/compare/pwm requirements param no. sym characteristic min typ? max units conditions 50 tccl ccp input low time no prescaler 0.5t cy + 20* ? ? ns with prescaler pic16f62x 10* ? ? ns pic16lf62x 20* ? ? ns 51 tcch ccp input high time no prescaler 0.5t cy + 20* ? ? ns with prescaler pic16f62x 10* ? ? ns pic16lf62x 20* ? ? ns 52 tccp ccp input period 3t cy + 40 * n ? ? ns n = prescale value (1,4 or 16) 53 tccr ccp output rise time pic16f62x 10 25* ns pic16lf62x 25 45* ns 54 tccf ccp output fall time pic16f62x 10 25* ns pic16lf62x 25 45* ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. (capture mode) 50 51 52 53 54 rb3/ccp1 (compare or pwm mode) rb3/ccp1
pic16f627a/628a/648a ds40044a-page 146 preliminary ? 2002 microchip technology inc. figure 17-11: timer0 clock timing table 17-9: timer0 clock requirements parameter no. sym characteristic min typ? max units conditions 40 tt0h t0cki high pulse width no prescaler 0.5 t cy + 20* ? ? ns with prescaler 10* ? ? ns 41 tt0l t0cki low pulse width no prescaler 0.5 t cy + 20* ? ? ns with prescaler 10* ? ? ns 42 tt0p t0cki period t cy + 40 * n ? ? ns n = prescale value (1, 2, 4, ..., 256) * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. 41 42 40 ra4/t0cki tmr0
? 2002 microchip technology inc. preliminary ds40044a-page 147 pic16f627a/628a/648a 18.0 dc and ac characteristics graphs and tables not available at this time.
pic16f627a/628a/648a ds40044a-page 148 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 149 pic16f627a/628a/648a 19.0 packaging information 19.1 package marking information * standard picmicro device marking consists of microchip part number, year code, week code, and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price. 20-lead ssop 18-lead soic (.300") 18-lead pdip (.300") example example example 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example xxxxxxxxxxxxxx yywwnnn xxxxxxxxxxxxxx pic16f627a-i/p 0210017 yywwnnn xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx 0210017 pic16f628a yywwnnn xxxxxxxxxxx xxxxxxxxxxx 0210017 pic16f648a 16f628a 0210017 -i/ml -e/so -i/ss legend: xx...x customer specific information * yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code note: in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line thus limiting the number of available characters for customer specific information.
pic16f627a/628a/648a ds40044a-page 150 preliminary ? 2002 microchip technology inc. 18-lead plastic dual in-line (p) ? 300 mil (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 9.40 7.87 .430 .370 .310 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.46 1.14 .070 .058 .045 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 22.99 22.80 22.61 .905 .898 .890 d overall length 6.60 6.35 6.10 .260 .250 .240 e1 molded package width 8.26 7.94 7.62 .325 .313 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.68 3.30 2.92 .145 .130 .115 a2 molded package thickness 4.32 3.94 3.56 .170 .155 .140 a top to seating plane 2.54 .100 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches* units 1 2 d n e1 c eb e p a2 l b1 b a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-001 drawing no. c04-007 significant characteristic
? 2002 microchip technology inc. preliminary ds40044a-page 151 pic16f627a/628a/648a 18-lead plastic small outline (so) ? wide, 300 mil (soic) foot angle 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.30 0.27 0.23 .012 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 11.73 11.53 11.33 .462 .454 .446 d overall length 7.59 7.49 7.39 .299 .295 .291 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches* units l c h 45 1 2 d p n b e1 e a2 a1 a * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-013 drawing no. c04-051 significant characteristic
pic16f627a/628a/648a ds40044a-page 152 preliminary ? 2002 microchip technology inc. 20-lead plastic shrink small outline (ss) ? 209 mil, 5.30 mm (ssop) 10 5 0 10 5 0 mold draft angle bottom 10 5 0 10 5 0 mold draft angle top 0.38 0.32 0.25 .015 .013 .010 b lead width 203.20 101.60 0.00 8 4 0 foot angle 0.25 0.18 0.10 .010 .007 .004 c lead thickness 0.94 0.75 0.56 .037 .030 .022 l foot length 7.34 7.20 7.06 .289 .284 .278 d overall length 5.38 5.25 5.11 .212 .207 .201 e1 molded package width 8.18 7.85 7.59 .322 .309 .299 e overall width 0.25 0.15 0.05 .010 .006 .002 a1 standoff 1.83 1.73 1.63 .072 .068 .064 a2 molded package thickness 1.98 1.85 1.73 .078 .073 .068 a overall height 0.65 .026 p pitch 20 20 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d p n b e e1 l c a2 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-150 drawing no. c04-072 significant characteristic
? 2002 microchip technology inc. preliminary ds40044a-page 153 pic16f627a/628a/648a 28-lead plastic quad flat no lead package (ml) 6x6 mm body (qfn) lead width *controlling parameter notes: mold draft angle top b .009 12 .011 .014 0.23 12 0.28 0.35 d pitch number of pins overall width standoff molded package length overall length molded package width molded package thickness overall height max units dimension limits a2 a1 e1 d d1 e n p a .026 .236 bsc .000 .226 bsc inches .026 bsc min 28 nom max 0.65 .031 .002 0.00 6.00 bsc 5.75 bsc millimeters* .039 min 28 0.65 bsc nom 0.80 0.05 1.00 e e1 n 1 2 d1 a a2 exposed metal pads bottom view .008 ref. base thickness a3 0.20 ref. top view 0.85 .033 .0004 0.01 .236 bsc .226 bsc 6.00 bsc 5.75 bsc q l lead length tie bar width l .020 .024 .030 0.50 0.60 0.75 r .005 .007 .010 0.13 0.17 0.23 tie bar length q .012 .016 .026 0.30 0.40 0.65 chamfer ch .009 .017 .024 0.24 0.42 0.60 r p a1 a3 ch x 45 b d2 e2 e2 d2 exposed pad width exposed pad length .140 .146 .152 3.55 3.70 3.85 .140 .146 .152 3.55 3.70 3.85 dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per si de. jedec equivalent: m0-220 drawing no. c04-114
pic16f627a/628a/648a ds40044a-page 154 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 155 pic16f627a/628a/648a appendix a: data sheet revision history revision a this is a new data sheet. appendix b: device differences the differences between the pic16f627a/628a/648a devices listed in this data sheet are shown in table b-1. table b-1: device differences device memory flash program ram data eeprom data pic16f627a 1024 x 14 224 x 8 128 x 8 pic16f628a 2048 x 14 224 x 8 128 x 8 pic16f648a 4096 x 14 256 x 8 256 x 8
pic16f627a/628a/648a ds40044a-page 156 preliminary ? 2002 microchip technology inc. appendix c: device migrations this section describes the functional and electrical specification differences when migrating between func- tionally similar devices. (such as from a pic16f627 to a pic16f627a). c.1 pic16f627/628 to a pic16f627a/628a 1. er mode is now rc mode. 2. code protection for the program memory has changed from code protect sections of memory to code protect of the whole memory. the con- figuration bits cp0 and cp1 in the pic16f627/ 628 do not exist in the pic16f627a/628a. they have been replaced with one configuration bit<13> cp. 3. ?brown-out detect (bod)? terminology has changed to ?brown-out reset (bor)? to better represent the function of the brown-out circuitry. 4. enabling brown-out reset (bor) does not auto- matically enable the power-up timer (pwrt) the way it did in the pic16f627/628. 5. intrc is now called intosc. 6. timer1 oscillator is now designed for 32.768 khz operation. in the pic16f627/628 the timer1 oscillator was designed to run up to 200 khz. 7. the dual speed oscillator mode only works in the intosc oscillator mode. in the pic16f627/ 628 the dual speed oscillator mode worked in both the intrc and er oscillator modes. appendix d: migrating from other picmicro devices this discusses some of the issues in migrating from other picmicro devices to the pic16f627a/628a/648a family of devices. d.1 pic16c62x/ce62x to pic16f627a/628a/ 648a migration see microchip web site for availability (www.microchip.com). d.2 pic16c622a to pic16f627a/628a/648a migration see microchip web site for availability (www.microchip.com). note: this device has been designed to perform to the parameters of its data sheet. it has been tested to an electrical specification designed to determine its conformance with these parameters. due to process differences in the manufacture of this device, this device may have different performance characteristics than its earlier version. these differences may cause this device to perform differently in your application than the earlier version of this device.
? 2002 microchip technology inc. preliminary ds40044a-page 157 pic16f627a/628a/648a appendix e: development tool version requirements this lists the minimum requirements (software/ firmware) of the specified development tool to support the devices listed in this data sheet. mplab ? ide: tbd mplab ? simulator: tbd mplab ? ice 3000: pic16f627a/628a/648a processor module: part number - tbd pic16f627a/628a/648a device adapter: socket part number 18-pin pdip tbd 18-pin soic tbd 20-pin ssop tbd 28-pin qfn tbd mplab ? icd: tbd pro mate ? ii: tbd picstart ? plus: tbd mpasm tm assembler: tbd mplab ? c18 c compiler: tbd note: please read all associated readme.txt files that are supplied with the develop- ment tools. these "read me" files will dis- cuss product support and any known limitations.
pic16f627a/628a/648a ds40044a-page 158 preliminary ? 2002 microchip technology inc. notes:
? 2002 microchip technology inc. preliminary ds40044a-page 159 pic16f627a/628a/648a on-line support microchip provides on-line support on the microchip world wide web site. the web site is used by microchip as a means to make files and information easily available to customers. to view the site, the user must have access to the internet and a web browser, such as netscape ? or microsoft ? internet explorer. files are also available for ftp download from our ftp site. connecting to the microchip internet web site the microchip web site is available at the following url: www.microchip.com the file transfer site is available by using an ftp ser- vice to connect to: ftp://ftp.microchip.com the web site and file transfer site provide a variety of services. users may download files for the latest development tools, data sheets, application notes, user's guides, articles and sample programs. a vari- ety of microchip specific business information is also available, including listings of microchip sales offices, distributors and factory representatives. other data available for consideration is:  latest microchip press releases  technical support section with frequently asked questions  design tips  device errata  job postings  microchip consultant program member listing  links to other useful web sites related to microchip products  conferences for products, development systems, technical information and more  listing of seminars and events systems information and upgrade hot line the systems information and upgrade line provides system users a listing of the latest versions of all of microchip's development systems software products. plus, this line provides information on how customers can receive the most current upgrade kits.the hot line numbers are: 1-800-755-2345 for u.s. and most of canada, and 1-480-792-7302 for the rest of the world.
pic16f627a/628a/648a ds40044a-page 160 preliminary ? 2002 microchip technology inc. reader response it is our intention to provide you with the best documen- tation possible to ensure successful use of your micro- chip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds40044a pic16f627a/628a/648a 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2002 microchip technology inc. preliminary ds40044a-page 161 pic16f627a/628a/648a index a a/d special event trigger (ccp)....................................... 57 absolute maximum ratings .............................................. 131 addlw instruction ........................................................... 113 addwf instruction ........................................................... 113 andlw instruction ........................................................... 113 andwf instruction ........................................................... 113 architectural overview .......................................................... 9 assembler mpasm assembler ................................................... 125 b baud rate error .................................................................. 71 baud rate formula ............................................................. 71 bcf instruction ................................................................. 114 block diagrams comparator i/o operating modes .......................................... 62 modified comparator output .............................. 64 i/o ports rb0/int pin ........................................................ 37 rb1/rx/dt pin ................................................... 37 rb2/tx/ck pin ................................................... 38 rb3/ccp1 pin .................................................... 38 rb4/pgm pin ..................................................... 39 rb5 pin............................................................... 40 rb6/t1oso/t1cki pin ...................................... 41 rb7/t1osi pin ................................................... 42 rc oscillator mode..................................................... 96 usart receive.......................................................... 79 usart transmit ......................................................... 77 brgh bit ............................................................................. 71 brown-out reset (bor) ..................................................... 98 bsf instruction ................................................................. 114 btfsc instruction............................................................. 114 btfss instruction ............................................................. 115 c call instruction ............................................................... 115 capture (ccp module) ....................................................... 56 block diagram............................................................. 56 ccp pin configuration................................................ 56 ccpr1h:ccpr1l registers...................................... 56 changing between capture prescalers...................... 56 prescaler..................................................................... 56 software interrupt ....................................................... 56 timer1 mode selection ............................................... 56 capture/compare/pwm (ccp)........................................... 55 capture mode. see capture ccp1 .......................................................................... 55 ccpr1h register............................................... 55 ccpr1l register ............................................... 55 ccp2 .......................................................................... 55 compare mode. see compare pwm mode. see pwm timer resources......................................................... 55 ccp1con register ccp1m3:ccp1m0 bits............................................... 55 ccp1x:ccp1y bits .................................................... 55 ccp2con register ccp2m3:ccp2m0 bits............................................... 55 ccp2x:ccp2y bits .................................................... 55 clocking scheme/instruction cycle .................................... 13 clrf instruction............................................................... 115 clrw instruction.............................................................. 116 clrwdt instruction......................................................... 116 code examples data eeprom refresh routine ................................ 92 code protection ................................................................ 108 comf instruction.............................................................. 116 comparator block diagrams i/o operating modes .......................................... 62 modified comparator output .............................. 64 comparator module.................................................... 61 configuration .............................................................. 62 interrupts .................................................................... 65 operation.................................................................... 63 reference ................................................................... 63 compare (ccp module) ..................................................... 56 block diagram ............................................................ 56 ccp pin configuration ............................................... 57 ccpr1h:ccpr1l registers ..................................... 56 software interrupt ....................................................... 57 special event trigger ................................................. 57 timer1 mode selection............................................... 57 configuration bits ............................................................... 93 crystal operation................................................................ 95 d data eeprom memory...................................................... 89 eecon1 register ...................................................... 89 eecon2 register ...................................................... 89 operation during code protection ............................. 92 reading ...................................................................... 91 spurious write protection ........................................... 91 using .......................................................................... 92 write verify ................................................................. 91 writing to .................................................................... 91 data memory organization................................................. 15 decf instruction .............................................................. 116 decfsz instruction.......................................................... 117 development support ....................................................... 125 development tool version requirements ........................ 157 device differences............................................................ 155 device migrations ............................................................. 156 dual-speed oscillator modes.............................................. 97 e eecon1 register ................................................................ 90 eecon2 register ................................................................ 90 errata .................................................................................... 3 external crystal oscillator circuit ....................................... 95 g general-purpose register file ........................................... 15 goto instruction.............................................................. 117 i i/o ports ............................................................................. 31 bi-directional .............................................................. 44 block diagrams rb0/int pin........................................................ 37 rb1/rx/dt pin................................................... 37 rb2/tx/ck pin................................................... 38 rb3/ccp1 pin.................................................... 38 rb4/pgm pin ..................................................... 39
pic16f627a/628a/648a ds40044a-page 162 preliminary ? 2002 microchip technology inc. rb5 pin............................................................... 40 rb6/t1oso/t1cki pin ...................................... 41 rb7/t1osi pin ................................................... 42 porta ........................................................................ 31 portb........................................................................ 36 programming considerations ..................................... 44 successive operations ............................................... 44 trisa ......................................................................... 31 trisb ......................................................................... 36 icepic in-circuit emulator ............................................... 126 id locations ...................................................................... 108 incf instruction ................................................................ 118 incfsz instruction............................................................ 118 in-circuit serial programming ........................................... 109 indirect addressing, indf and fsr registers.................... 28 instruction flow/pipelining .................................................. 13 instruction set addlw ..................................................................... 113 addwf ..................................................................... 113 andlw ..................................................................... 113 andwf ..................................................................... 113 bcf ........................................................................... 114 bsf ........................................................................... 114 btfsc ...................................................................... 114 btfss ...................................................................... 115 call ......................................................................... 115 clrf......................................................................... 115 clrw........................................................................ 116 clrwdt................................................................... 116 comf ....................................................................... 116 decf ........................................................................ 116 decfsz.................................................................... 117 goto........................................................................ 117 incf.......................................................................... 118 incfsz ..................................................................... 118 iorlw....................................................................... 119 iorwf ...................................................................... 119 movf........................................................................ 119 movlw..................................................................... 119 movwf .................................................................... 120 nop .......................................................................... 120 option .................................................................... 120 retfie ..................................................................... 120 retlw...................................................................... 121 return ................................................................... 121 rlf ........................................................................... 121 rrf........................................................................... 122 sleep ...................................................................... 122 sublw...................................................................... 122 subwf ..................................................................... 123 swapf ..................................................................... 123 tris .......................................................................... 123 xorlw ..................................................................... 124 xorwf..................................................................... 124 instruction set summary................................................... 111 int interrupt ...................................................................... 105 intcon register ................................................................ 24 interrupt sources capture complete (ccp) ............................................ 56 compare complete (ccp) .......................................... 57 tmr2 to pr2 match (pwm) ....................................... 58 interrupts ........................................................................... 104 interrupts, enable bits ccp1 enable (ccp1ie bit)......................................... 56 interrupts, flag bits ccp1 flag (ccp1if bit)............................................. 56 iorlw instruction ............................................................ 119 iorwf instruction ............................................................ 119 k keeloq evaluation and programming tools .................... 128 m memory organization data eeprom memory.................................. 89, 91, 92 migrating from other picmicro devices ............................ 156 movf instruction.............................................................. 119 movlw instruction........................................................... 119 movwf instruction .......................................................... 120 mplab c17 and mplab c18 c compilers ..................... 125 mplab icd in-circuit debugger ...................................... 127 mplab ice high performance universal in-circuit emulator with mplab ide ............................................................... 126 mplab integrated development environment software.. 125 mplink object linker/mplib object librarian ................ 126 n nop instruction ................................................................ 120 o option instruction .......................................................... 120 option register................................................................ 23 oscillator configurations..................................................... 95 oscillator start-up timer (ost) .......................................... 98 p package marking information ........................................... 149 packaging information ...................................................... 149 pcl and pclath............................................................... 28 stack ........................................................................... 28 pcon register ................................................................... 27 picdem 1 low cost picmicro demonstration board ...... 127 picdem 17 demonstration board.................................... 128 picdem 2 low cost pic16cxx demonstration board ... 127 picdem 3 low cost pic16cxxx demonstration board . 128 picstart plus entry level development programmer.. 127 pie1 register...................................................................... 25 pin functions rc6/tx/ck ........................................................... 69?86 rc7/rx/dt........................................................... 69?86 pir1 register ..................................................................... 26 port rb interrupt............................................................... 105 porta ............................................................................... 31 portb ............................................................................... 36 power control/status register (pcon).............................. 99 power-down mode (sleep) ............................................ 107 power-on reset (por) ...................................................... 98 power-up timer (pwrt) .................................................... 98 pr2 register ................................................................ 52, 58 pro mate ii universal device programmer ................... 127 program memory organization........................................... 15 pwm (ccp module) ........................................................... 58 block diagram ............................................................ 58 simplified pwm .................................................. 58 ccpr1h:ccpr1l registers...................................... 58 duty cycle .................................................................. 59 example frequencies/resolutions ............................. 59 period ......................................................................... 58 set-up for pwm operation......................................... 59 tmr2 to pr2 match ................................................... 58
? 2002 microchip technology inc. preliminary ds40044a-page 163 pic16f627a/628a/648a q q-clock ............................................................................... 59 quick-turnaround-production (qtp) devices ...................... 7 r rc oscillator ....................................................................... 96 rc oscillator mode block diagram............................................................. 96 registers maps pic16f627a ................................................. 16, 17 pic16f628a ................................................. 16, 17 reset................................................................................... 97 retfie instruction............................................................ 120 retlw instruction ............................................................ 121 return instruction ......................................................... 121 revision history ................................................................ 155 rlf instruction.................................................................. 121 rrf instruction ................................................................. 122 s serial communication interface (sci) module, see usart serialized quick-turnaround-production (sqtp) devices ... 7 sleep instruction ............................................................. 122 software simulator (mplab sim)..................................... 126 special event trigger. see compare special features of the cpu .............................................. 93 special function registers ................................................. 18 status register ................................................................... 22 sublw instruction............................................................ 122 subwf instruction ........................................................... 123 swapf instruction............................................................ 123 t t1ckps0 bit ....................................................................... 48 t1ckps1 bit ....................................................................... 48 t1oscen bit ...................................................................... 48 t1sync bit ......................................................................... 48 t2ckps0 bit ....................................................................... 53 t2ckps1 bit ....................................................................... 53 timer0 block diagrams timer0/wdt ....................................................... 46 external clock input.................................................... 45 interrupt....................................................................... 45 prescaler..................................................................... 46 switching prescaler assignment................................. 47 timer0 module ............................................................ 45 timer1 asynchronous counter mode ..................................... 50 capacitor selection..................................................... 51 external clock input.................................................... 49 external clock input timing ........................................ 50 oscillator ..................................................................... 51 prescaler............................................................... 49, 51 resetting timer1......................................................... 51 resetting timer1 registers......................................... 51 special event trigger (ccp)....................................... 57 synchronized counter mode ...................................... 49 timer mode ................................................................. 49 tmr1h........................................................................ 50 tmr1l ........................................................................ 50 timer2 block diagram............................................................. 52 postscaler ................................................................... 52 pr2 register................................................................ 52 prescaler .............................................................. 52, 59 timer2 module............................................................ 52 tmr2 output............................................................... 52 tmr2 to pr2 match interrupt..................................... 58 timing diagrams timer0....................................................................... 143 timer1....................................................................... 143 usart asynchronous receiver...................................... 80 usart asynchronous master transmission ............. 77 usart asynchronous reception .............................. 80 usart rx pin sampling ..................................... 75, 76 usart synchronous reception ................................ 86 usart synchronous transmission ........................... 84 timing diagrams and specifications ................................ 140 tmr0 interrupt.................................................................. 105 tmr1cs bit ........................................................................ 48 tmr1on bit........................................................................ 48 tmr2on bit........................................................................ 53 toutps0 bit ...................................................................... 53 toutps1 bit ...................................................................... 53 toutps2 bit ...................................................................... 53 toutps3 bit ...................................................................... 53 tris instruction ................................................................ 123 trisa ................................................................................. 31 trisb ................................................................................. 36 u universal synchronous asynchronous receiver transmitter (usart) ............................................................................. 69 asynchronous receiver setting up reception.......................................... 82 asynchronous receiver mode address detect ................................................... 82 block diagram .................................................... 82 usart asynchronous mode................................................... 76 asynchronous receiver.............................................. 79 asynchronous reception............................................ 81 asynchronous transmission....................................... 77 asynchronous transmitter.......................................... 76 baud rate generator (brg) ...................................... 71 block diagrams transmit.............................................................. 77 usart receive ................................................. 79 brgh bit .................................................................... 71 sampling......................................................... 72, 73, 74 synchronous master mode......................................... 83 synchronous master reception ................................. 85 synchronous master transmission ............................ 83 synchronous slave mode........................................... 86 synchronous slave reception ................................... 87 synchronous slave transmit...................................... 86 v voltage reference configuration .............................................................. 67 voltage reference module ......................................... 67 w watchdog timer (wdt).................................................... 106 www, on-line support ....................................................... 3
pic16f627a/628a/648a ds40044a-page 164 preliminary ? 2002 microchip technology inc. x xorlw instruction ........................................................... 124 xorwf instruction ........................................................... 124
? 2002 microchip technology inc. preliminary ds40044a-page 165 pic16f627a/628a/648a product identification system to order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office. * jw devices are uv erasable and can be programmed to any device configuration. jw devices meet the electrical requirement of each oscillator type. sales and support part no. -x /xx xxx pattern package temperature range device device pic16f627a/628a/648a:standard v dd range 3.0v to 5.5v pic16f627a/628a/648atv dd range 3.0v to 5.5v (tape and reel) pic16lf627a/628a/648a:v dd range 2.0v to 5.5v pic16lf627a/628a/648at:v dd range 2.0v to 5.5v (tape and reel) temperature range i = -40 c to +85 c e = -40 c to +125 c package p = pdip so = soic (gull wing, 300 mil body) ss = ssop (209 mil) ml = qfn (28 lead) pattern 3-digit pattern code for qtp (blank otherwise). examples: a) pic16f627a - e/p 301 = extended temp., pdip package, 20 mhz, normal v dd limits, qtp pattern #301. b) pic16lf627a - i/so = industrial temp., soic package, 20 mhz, extended v dd limits. data sheets products supported by a preliminary data sheet may have an errata sheet describing minor operational differences and recom- mended workarounds. to determine if an errata sheet exists for a particular device, please contact one of the following: 1. your local microchip sales office 2. the microchip corporate literature center u.s. fax: (480) 792-7277 3. the microchip worldwide site (www.microchip.com) please specify which device, revision of silicon and data sheet (include literature #) you are using. new customer notification system register on our web site (www.microchip.com/cn) to receive the most current information on our products.
ds40044a-page 166 preliminary ? 2002 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: 480-792-7627 web address: http://www.microchip.com rocky mountain 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7966 fax: 480-792-4338 atlanta 3780 mansell road, suite 130 alpharetta, ga 30022 tel: 770-640-0034 fax: 770-640-0307 boston 2 lan drive, suite 120 westford, ma 01886 tel: 978-692-3848 fax: 978-692-3821 chicago 333 pierce road, suite 180 itasca, il 60143 tel: 630-285-0071 fax: 630-285-0075 dallas 4570 westgrove drive, suite 160 addison, tx 75001 tel: 972-818-7423 fax: 972-818-2924 detroit tri-atria office building 32255 northwestern highway, suite 190 farmington hills, mi 48334 tel: 248-538-2250 fax: 248-538-2260 kokomo 2767 s. albright road kokomo, indiana 46902 tel: 765-864-8360 fax: 765-864-8387 los angeles 18201 von karman, suite 1090 irvine, ca 92612 tel: 949-263-1888 fax: 949-263-1338 san jose microchip technology inc. 2107 north first street, suite 590 san jose, ca 95131 tel: 408-436-7950 fax: 408-436-7955 toronto 6285 northam drive, suite 108 mississauga, ontario l4v 1x5, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia microchip technology australia pty ltd suite 22, 41 rawson street epping 2121, nsw australia tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing microchip technology consulting (shanghai) co., ltd., beijing liaison office unit 915 bei hai wan tai bldg. no. 6 chaoyangmen beidajie beijing, 100027, no. china tel: 86-10-85282100 fax: 86-10-85282104 china - chengdu microchip technology consulting (shanghai) co., ltd., chengdu liaison office rm. 2401-2402, 24th floor, ming xing financial tower no. 88 tidu street chengdu 610016, china tel: 86-28-86766200 fax: 86-28-86766599 china - fuzhou microchip technology consulting (shanghai) co., ltd., fuzhou liaison office unit 28f, world trade plaza no. 71 wusi road fuzhou 350001, china tel: 86-591-7503506 fax: 86-591-7503521 china - shanghai microchip technology consulting (shanghai) co., ltd. room 701, bldg. b far east international plaza no. 317 xian xia road shanghai, 200051 tel: 86-21-6275-5700 fax: 86-21-6275-5060 china - shenzhen microchip technology consulting (shanghai) co., ltd., shenzhen liaison office rm. 15-16, 13/f, shenzhen kerry centre, renminnan lu shenzhen 518001, china tel: 86-755-82350361 fax: 86-755-82366086 china - hong kong sar microchip technology hongkong ltd. unit 901-6, tower 2, metroplaza 223 hing fong road kwai fong, n.t., hong kong tel: 852-2401-1200 fax: 852-2401-3431 india microchip technology inc. india liaison office divyasree chambers 1 floor, wing a (a3/a4) no. 11, o?shaugnessey road bangalore, 560 025, india tel: 91-80-2290061 fax: 91-80-2290062 japan microchip technology japan k.k. benex s-1 6f 3-18-20, shinyokohama kohoku-ku, yokohama-shi kanagawa, 222-0033, japan tel: 81-45-471- 6166 fax: 81-45-471-6122 korea microchip technology korea 168-1, youngbo bldg. 3 floor samsung-dong, kangnam-ku seoul, korea 135-882 tel: 82-2-554-7200 fax: 82-2-558-5934 singapore microchip technology singapore pte ltd. 200 middle road #07-02 prime centre singapore, 188980 tel: 65-6334-8870 fax: 65-6334-8850 taiwan microchip technology (barbados) inc., taiwan branch 11f-3, no. 207 tung hua north road taipei, 105, taiwan tel: 886-2-2717-7175 fax: 886-2-2545-0139 europe austria microchip technology austria gmbh durisolstrasse 2 a-4600 wels austria tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark microchip technology nordic aps regus business centre lautrup hoj 1-3 ballerup dk-2750 denmark tel: 45 4420 9895 fax: 45 4420 9910 france microchip technology sarl parc d?activite du moulin de massy 43 rue du saule trapu batiment a - ler etage 91300 massy, france tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany microchip technology gmbh steinheilstrasse 10 d-85737 ismaning, germany tel: 49-89-627-144 0 fax: 49-89-627-144-44 italy microchip technology srl centro direzionale colleoni palazzo taurus 1 v. le colleoni 1 20041 agrate brianza milan, italy tel: 39-039-65791-1 fax: 39-039-6899883 united kingdom microchip ltd. 505 eskdale road winnersh triangle wokingham berkshire, england rg41 5tu tel: 44 118 921 5869 fax: 44-118 921-5820 11/15/02 w orldwide s ales and s ervice


▲Up To Search▲   

 
Price & Availability of PIC16LF628A-EML

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X